How can I POST to multiple urls at the same time?

冷暖自知 提交于 2019-11-27 07:05:59

问题


Our website is hosted using EE. I've been tasked to add to our "Contact us" form so that it posts to an external sales lead generation system (hubspot)

We were given an URL to post to, and when I finally found the html for the form in question I noticed that it is already pointing to another sales lead system. I don't want to remove this URL. Is it possible to do two posts at the same time?

<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" 


http://yoursite.yourportal.hubspot.com/?app=leaddirector&FormName=X

回答1:


You can't do that with a single request. Use XMLHTTP objects or JQuery.post(); with different URL's and the same data. Simply send multiple requests. Alternatively, you could send one request to your server, where PHP can send it onwards to other pages, as well as other servers, evading the same-origin policy javascript has.




回答2:


You could give your form an id and instead of having a btton of type submit, you have a regular button with an id(in this example id is submit) and then using jquery do something like so on click of the button:

$("button#submit").click(function() {
    $.post("https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8", $("form#id").serialize(), function(data){
        //DO something
    });

    $.post("http://yoursite.yourportal.hubspot.com/?app=leaddirector&FormName=X", $('form#id').serialize(), function(data){
        //DO something 
    });
});


来源:https://stackoverflow.com/questions/10955097/how-can-i-post-to-multiple-urls-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!