2013-08-23 206 views
1

任何人都有任何想法如何在张贴照片和标签之间放置10秒的延迟?该脚本会在照片上传后立即生成标签,但我想要延迟。延迟ajax脚本

我想你使用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){ 

回答

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){ 

} 
0

可以使用setTimeout函数调用另一个函数与代码,你想在延迟后执行。

setTimeout(someFunction, millisecondDelay);