订购Ajax调用 [英] Ordering Ajax Calls

查看:97
本文介绍了订购Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想正在做是在一个特定的顺序,让我进一步解释使用一些code中的Ajax调用。

I want the ajax calls that are being made to be in a particular order, Let me explain further using some code.

var feed_urls = [
                       'URL_1',
                       'URL_2',
                       'URL_3',
                       ...
                       ...

                       'URL_N',
                       ];

我正在使用jQuery的的getJSON 方法,像这样的Ajax调用

I am making ajax calls using jquery's getJSON method like so

$.each(feed_urls,function(index,value){
                        $.getJSON(value, function(data) {
                            $.each(data.feed.entry,function(i,val){
                                   LIST.push(val.content.src);
                            });
                        });
                });

我现在面临的问题是,因为Ajax调用是异步的列表的内容并不总是以相同的顺序。反正是有解决这个问题?

The problem I am facing is that since ajax calls are asynchronous the content of LIST is not always in the same order. Is there anyway to solve this ?

URL_1 然后按 URL_2 的AJAX调用的preferable顺序,然后按 URL_3 等等,直到 URL_N

The preferable order of ajax calls would be URL_1 followed by URL_2 followed by URL_3 and so on till URL_N

推荐答案

使用ajaxSetup()与异步:假的,它会重新:

use ajaxSetup() with async :false, in it re:

$.ajaxSetup(
    {
    data: "{}",
    async false,
..whatever else you need

这篇关于订购Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆