I am new to jquery and Ajax and I have the following question.
Are multiple Ajax request allowed? I use PHP and I would like to have form submit via jquery Ajax and at the same time trigger another Ajax request that would do another task. All of this without the user waiting for every request to complete.
Is this possible?
Thanks for the help guys!
* Edit * I tried it but if i try to redirect the browser to another page it waits until ajax completes before moving on.
this is the code for my test.
/* populate subcategory dropdown based on category select */
$('#categoria-selector').change(function (e) {
var cat = $("#categoria-selector option:selected").text();
alert(cat);
$.ajax({
type: "POST",
url: baseurl + 'precios/test',
success: function (data, status, xhr) {
alert('second alert');
}
});
$.ajax({
type: "POST",
url: baseurl + 'precios/test2',
success: function (data, status, xhr) {
alert('third alert');
}
});
});
On my controller i have the following functions
function test() {
//sleep for 5 seconds
$first = date('Y-m-d H:m:s');
sleep(10);
$second = date('Y-m-d H:m:s');
//start again
$_SESSION['mivar'] = 'Started at ' . $first . ' and ended at ' . $second;
}
function test2() {
//sleep for 5 seconds
$first = date('Y-m-d H:m:s');
sleep(30);
$second = date('Y-m-d H:m:s');
//start again
$_SESSION['mivar2'] = 'Started at ' . $first . ' and ended at ' . $second;
}