- $(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请求建立一个新的页面
|