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条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)