Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Linkedin API人员搜索在javascript中停止一个方法的执行,直到另一个方法完成?_Javascript_Linkedin_Linkedin Jsapi - Fatal编程技术网

如何使用Linkedin API人员搜索在javascript中停止一个方法的执行,直到另一个方法完成?

如何使用Linkedin API人员搜索在javascript中停止一个方法的执行,直到另一个方法完成?,javascript,linkedin,linkedin-jsapi,Javascript,Linkedin,Linkedin Jsapi,我正在从for循环调用.API.PeopleSearch()中的,,这个for循环在ajax成功方法中,但是在完成for循环执行之前,会调用ajax方法complete 我想停止,直到for循环完成 $.ajax({ type: 'GET', dataType: 'json', url: "get_data.htm", async : false, success: function(data, textStatus

我正在从for循环调用.API.PeopleSearch()中的
,这个for循环在ajax成功方法中,但是在完成for循环执行之前,会调用ajax方法complete

我想停止,直到for循环完成

$.ajax({
        type: 'GET',
        dataType: 'json',
        url: "get_data.htm",
        async : false,
        success: function(data, textStatus ){
            for(i in data){
                searchClick(data[i].firstName,data[i].lastName);
                }
                alert(resultArray);//here i want to send the response to server side
            }
        },
        error: function(xhr, textStatus, errorThrown){
           alert('request failed');
        }
      });
以下是我的searchClick功能:

function searchClick(firstName, secondName) {
  if (!IN.ENV.auth.oauth_token) {
    alert("You must login w/ LinkedIn to use the Search functionality!");
    return;
  }

  IN.API.PeopleSearch()
      .fields("id", "firstName", "lastName","emailAddress","headline","industry","pictureUrl","positions",
            "summary","numConnections")
    .params({
      "first-name": firstName,
      "last-name": secondName
    })
    .result(function(result, metadata) {

    for (i in result.people.values) {
          try{
              resultArray[i] = result.people.values[i];
          }catch(err){
              alert(err);
              }
    }

    });
}

alert(resultArray)
在for循环完成之前被调用,如何处理

我不知道我是否明白你的问题,但也许类似的东西对你有用:(未测试)



我不知道你到底在做什么,但可以说我们有一个方法,异步

    Function.prototype.async = function () {
        setTimeout.bind(null, this, 0).apply(null, arguments);
        };
这允许我编写如下代码:

   alert.async("This will be displayed later.");
   alert("This will be displayed first.");
因此,一旦其他事件完成,将调用带有.async的代码


否则,在您的情况下,请使用

 if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
检查文档是否准备就绪,然后发送/填写/成功。这是原始的AJAX方法。:)


O希望这可能会有所帮助:)

您不需要为循环阻塞正常的
,而是异步重写它。这是一个很好的起点。Hi@DCoder谢谢你的回复,你能给我推荐我将非常感谢你的代码吗。Hi@DCoder我无法用async编写代码。eachSeries你能给我一些建议吗。也许你可以为此实现一个简单的队列,当队列完成后,做你想做的。这意味着在回调时没有定义队列(数据[i],排队);太棒了…它的工作如预期,我挣扎了2天。。非常感谢你。。。
   alert.async("This will be displayed later.");
   alert("This will be displayed first.");
 if(xmlhttp.readyState == 4 && xmlhttp.status == 200)