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

后端 未结 2 2075
慢半拍i
慢半拍i 2020-12-11 09: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 g

相关标签:
2条回答
  • 2020-12-11 10:04

    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.

    0 讨论(0)
  • 2020-12-11 10:14

    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 
        });
    });
    
    0 讨论(0)
提交回复
热议问题