douke1891 2012-10-23 08:32
浏览 114
已采纳

来自浏览器的两个并行请求[重复]

Possible Duplicate:
Parallel asynchronous Ajax requests using jQuery

I need to create 2 ajax requests one after the other. And then display the result of the one that has finished first. The problem is that second one always waits for first one to finish. I tried to abort first one but still the second is waiting for first one to finish. Is there any workaround?

Basically first one calls php script that parses some XML file and inserts records into a MySQL table. Second one calls PHP script which needs to return 20 records that first one has imported.

I tried with two ajax calls and the first one called from iframe. But result is always same. Second one is waiting for the first one to finish. Only way around that I find is to create subdomain and call first one with subdomain. But this not working in IE.

Can anybody explain how solve this?

Maybe I need to describe my problem more. First I call ajax that execution time is cca 2 min and while first one is in execution I need to have multiple requests that will retrive records that are imported by first one.

  • 写回答

2条回答 默认 最新

  • duanfuxing2417 2012-10-23 08:50
    关注

    Call them sequentially. After you call the first one, it'll be executing in asynchronous manner. Then you call the second one. At that time first request will be still running. But its not guarranteed that second request will be sent just after first one. So you can have some timeout. See the example bellow.

    $.post('ajax/first_call', function(data) {
        // process returned data of first ajax call
    });
    window.setTimeout(function(){
        $.post('ajax/second_call', function(data) {
            // process returned data of second ajax call
        });
    }, 2000);
    

    Here the second ajax call is requested after 2 second. And it does not depend on first call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度