weixin_33736048 2015-08-24 19:03 采纳率: 0%
浏览 34

并发Ajax调用?

I need to call a particular PHP script on my server several times. As each call will take some time (e.g. about .5 seconds) and each call is independent of each other, I want to call the scripts concurrently. Right now, I have something like this:

$(document).ready(function() {

    $.ajax({
      url: 'main.php',
      method: 'POST',
      data: { foo: 'foo' },
      success: function(result) {
        console.log(result);
      }
    });

    $.ajax({
      url: 'main.php',
      method: 'POST',
      data: { bar: 'bar' },
      success: function(result) {
        console.log(result);
      }
    });

});

Instead of making these calls sequentially, I want to do them concurrently. How do I do that?

  • 写回答

3条回答 默认 最新

  • weixin_33674976 2015-08-24 19:06
    关注

    Set your async = true on your AJAX calls to make them asynchronous.

    $.ajax({
        async: "true",
          url: 'main.php',
          method: 'POST',
          data: { foo: 'foo' },
          success: function(result) {
            console.log(result);
          }
        });
    
        $.ajax({
        async: "true",
          url: 'main.php',
          method: 'POST',
          data: { bar: 'bar' },
          success: function(result) {
            console.log(result);
          }
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。