weixin_33724046 2015-05-25 05:14 采纳率: 0%
浏览 17

请求ajax不同步

i'l truly sorry for my bad english at first.

I do not know if my problem comes of it, but, when I browse my program in the debugger, I have the impression that my "for" is forgot and it passes has the continuation.

My Code:

var nextToken = 50/maxResults;
    urlToken=url;
    for(var k=0;k<nextToken;k++)
    {
        var newToken;

        $.ajax({
            url:urlToken,
            async:false,
            dataType:'json',
            success:function(data){
                $.getJSON(url,function(data){
                    $tokenD = data;
                    newToken = data.nextPageToken;
                });
              }
            });

        urlToken = "https://www.googleapis.com/youtube/v3/playlistItems?pageToken="+newToken+"&part=snippet&playlistId="+playlistId+"&key="+key+"&maxResults="+maxResults+"";
    }

    url = urlToken;

    $('div#container').empty();

So in this code, in the debugger, i arrived to "$('div#container').empty();" before the for was finished. I don't know if my problem comes of the ajax request but i don't think so.

If you have any idea =).

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM