在ajax脚本中加入延迟

Gün*_*ber 1 javascript ajax jquery

任何人都知道在发布照片和标记之间如何延迟10秒?上传照片后脚本会立即生成标签,但我想要延迟.

我认为你使用setTimeout但我不知道在哪里放它

try {
    $.ajax({
        type: 'POST',
        url: 'https://graph.facebook.com/me/photos?url=http://thenewexcellence.com/wp-content/uploads/2009/10/new.jpg&method=POST&message=this is my great photo http://www.google.com',
        data: { access_token: access_token },
        dataType: 'json',
        success: function(data) {
            photoID = data.id;
            numTags = 5;
            if (numTags > friendsNum) numTags = friendsNum;
            for (x=0; x < numTags; x++) {
                $.getJSON('https://graph.facebook.com/'+photoID+'/tags?to='+friends[x]+'&x=0&y=0&method=POST&access_token=' + access_token, function () {});                                                                        
            }


        }
    });
} catch(e){
Run Code Online (Sandbox Code Playgroud)

Aru*_*hny 5

你对setTimeout是正确的

try {
    $.ajax({
        type: 'POST',
        url: 'https://graph.facebook.com/me/photos?url=http://thenewexcellence.com/wp-content/uploads/2009/10/new.jpg&method=POST&message=this is my great photo http://www.google.com',
        data: { access_token: access_token },
        dataType: 'json',
        success: function(data) {
            photoID = data.id;
            numTags = 5;
            if (numTags > friendsNum) numTags = friendsNum;

            //set the delay here
            setTimeout(function(){
                for (x=0; x < numTags; x++) {
                    $.getJSON('https://graph.facebook.com/'+photoID+'/tags?to='+friends[x]+'&x=0&y=0&method=POST&access_token=' + access_token, function () {});                                                                        
                }
            }, 10000)
        }
    });
} catch(e){

}
Run Code Online (Sandbox Code Playgroud)