Home >Web Front-end >JS Tutorial >Jquery code to handle multiple ajax requests at one time_jquery

Jquery code to handle multiple ajax requests at one time_jquery

WBOY
WBOYOriginal
2016-05-16 18:02:351006browse
Copy code The code is as follows:

$(document).ready(function () {
$ ('#getsetgo').click(function () {
$.when($.ajax("page1.php"), $.ajax("page2.php")).done(function(a1, a2 ){
$('#id1').html(a1[0]);
$('#id2').html(a2[0]);
});
} );
});

After the release of jquery 1.5, a new method jQuery.when(). can handle multiple ajax requests at one time. See jquery api documentation for more details.
Collection by Ancker

Another way jquery handles multiple ajax requests on the same page
Add a parameter
Copy code The code is as follows:

$.post(
"doSysthFile.aspx",
{
type: '1 '
},
function(data, textStatus)
{
},
"json");
$.post(
"doSysthFile.aspx",
{
type: '2'
},
function(data, textStatus)
{
},
"json");

In the doSysthFile.aspx.cs file:
Copy the code The code is as follows:

if (( !string.IsNullOrEmpty(Request["type"])) && (Request["type"] == "1"))
{
//do something
}
if ((! string.IsNullOrEmpty(Request["type"])) && (Request["type"] == "2"))
{
//do something
}

This different ajax request can be processed by the same page, and there is no need to create a new page for each ajax request.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn