'How can I perform an ajax post to 2 php scripts at the same time?
I am using the following ajax function to post to a php script. (url_one.php)
How could I post the same data (myvar1, myvar2) to a second php script (ajaxURL2) at the same time ? Is there a way to do this ?
function ajax_function() {
var myvar1 = $('myvar1').val();
var myvar2 = $('.myvar2:checked').val();
var ajaxURL = window.location.protocol + "//" + window.location.host + "/"+"url_one.php";
var ajaxURL2 = window.location.protocol + "//" + window.location.host + "/"+"url_two.php"; // <-- to 2nd url simultaneously
$.ajax({
async: false,
type: "POST",
url: ajaxURL,
timeout : 8000,
data: {functionname: 'my_php_function', arguments: [myvar1, myvar2]},
success: function (data) {
if( !('error' in data) ) {
objDiv.scrollTop = objDiv.scrollHeight;
}},
});
}
The ajax function is being called every five seconds using setTimeout .. (and never misses a beat..)
setTimeout(function(){
ajax_function() ;
//... something here ?
}, 5000);
Should I be looking at this part, to post to more than one script at the same time? or be looking into a php side solution. Many thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
