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.

    评论

报告相同问题?