$(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]);
});
});
});
jquery 1.5发布后,其中新增加方法jquery.when().可以一次处理多个ajax请求。更多详细情况查看jquery api文档。
collection by ancker
jquery 同一个页面处理多个ajax请求的另外一种方法
加一个参数
复制代码 代码如下:
$.post(
dosysthfile.aspx,
{
type: '1'
},
function(data, textstatus)
{
},
json);
$.post(
dosysthfile.aspx,
{
type: '2'
},
function(data, textstatus)
{
},
json);
在dosysthfile.aspx.cs文件中:
复制代码 代码如下:
if ((!string.isnullorempty(request[type])) && (request[type] == 1))
{
//do something
}
if ((!string.isnullorempty(request[type])) && (request[type] == 2))
{
//do something
}
这个不同的ajax就可以请求同一个页面处理了,不需求为每个ajax请求建立一个新的页面