Discuz教程网

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

[复制链接]
authicon dly 发表于 2011-9-6 20:24:16 | 显示全部楼层 |阅读模式
  1. $(document).ready(function () {
  2. $('#getsetgo').click(function () {
  3. $.when($.ajax("page1.php"), $.ajax("page2.php")).done(function(a1, a2){
  4. $('#id1').html(a1[0]);
  5. $('#id2').html(a2[0]);
  6. });
  7. });
  8. });
复制代码

jquery 1.5发布后,其中新增加方法jQuery.when().可以一次处理多个ajax请求。更多详细情况查看jquery api文档。
Collection by Ancker

jquery 同一个页面处理多个ajax请求的另外一种方法
加一个参数
  1. $.post(
  2. "doSysthFile.aspx",
  3. {
  4. type: '1'
  5. },
  6. function(data, textStatus)
  7. {
  8. },
  9. "json");
  10. $.post(
  11. "doSysthFile.aspx",
  12. {
  13. type: '2'
  14. },
  15. function(data, textStatus)
  16. {
  17. },
  18. "json");
复制代码

在doSysthFile.aspx.cs文件中:
  1. if ((!string.IsNullOrEmpty(Request["type"])) && (Request["type"] == "1"))
  2. {
  3. //do something
  4. }
  5. if ((!string.IsNullOrEmpty(Request["type"])) && (Request["type"] == "2"))
  6. {
  7. //do something
  8. }
复制代码

这个不同的ajax就可以请求同一个页面处理了,不需求为每个ajax请求建立一个新的页面



上一篇:jQuery验证Checkbox是否选中的代码 推荐
下一篇:基于jquery的loading 加载提示效果实现代
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-3 09:29

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表