您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Jquery 一次处理多个ajax请求的代码_jquery

2024/12/17 6:56:22发布13次查看
复制代码 代码如下:
$(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请求建立一个新的页面
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product