且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP,jQuery和放大器; Ajax调用乱序

更新时间:2023-01-23 19:17:28

您已经请求前创建的参考点,并把结果附加到他们:

You have to create reference points before the requests, and append the results to them:

var counter = 0;

function loadPage(target,url,append)
{
    if (append == true) {
        var id = "container_"+counter;
        $(target).append("<div id='"+id+"'></div>")
        $.get(url, function(data) { 
            $("#"+id).append(data);
        });
        counter++;
    } else {
        $(target).load(url);
    }

    return false;
}

您的参考元素将被附加到每 loadPage()通话的对象,所以他们会以正确的顺序,并要求能进来任何顺序将在他们的正确的地方进行加载。

Your reference elements will be appended to the target on every loadPage() call, so they will be in the correct order, and the request can come in any order they will be loaded in their right place.