weixin_33743248 2015-07-16 04:11 采纳率: 0%
浏览 99

Ajax请求响应顺序

I have small doubt about the ajax request

  1. If I send a couple of AJAX request, will response received in that same order ? req1, req2 and then response for req1 is received and then response for req2. Is there any possibility that response for req2 is first received ??

  2. I am not storing column_index value and when I receive response, Will it pickup correct column_index?

Code:

function make_ajax_call(column_index) {
    jQuery.ajax({
        url: site.adminajaxurl + '?action=display_items',
        type: 'POST',
        data: {
            id: dbase_header[column_index]
        },
        // dataType: "json",
        success: function(data) {

            // Until we get all responses hide the submit button
            jQuery('body')
                .find('#submit_template_div')
                .hide();

            // Store the html content received for a template
            data_html[column_index] = data;

            // Increase response count
            response_display_item++;

            // If all response received
            if (response_display_item == request_display_item) {
                // Reset request count and update framework
                response_display_item=0;
                request_display_item = 0;

                print_menu = 1;
                update_framework();
            }
        }
    });
}
  • 写回答

3条回答 默认 最新

  • 衫裤跑路 2015-07-16 04:16
    关注

    1) For asynchronous request, it depends on the time it takes for a specific operation to complete. Only once the operation is complete the response would be received by the client.

    If you need sequential order then you should be using synchronous calls to server. If you are using jquery.Ajax method, then you can specify the Async = false.

    From JQuery Docs

    The first letter in Ajax stands for "asynchronous," meaning that the operation occurs in parallel and the order of completion is not guaranteed. The async option to $.ajax() defaults to true, indicating that code execution can continue after the request is made. Setting this option to false (and thus making the call no longer asynchronous) is strongly discouraged, as it can cause the browser to become unresponsive.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)