开发者

Sequential web service call not working

A little (!) bit of background before I can get to the question : I am implementing a web based search solution. Technology used: javascript (jquery), .net, html etc. etc.

All my web service calls are done through javascript (cross domain ws call). I have few sequential web service calls which all have different success callback function.

I am not able to digest - when i call those ws individually in seperate places they are returning me proper results but sequentially sometime they are giving and sometime not.

sample code: this is not giving expected results all the time.

function submitSearchRequest(_queryString, Stores) { 
    if (Stores[1].length>0) {
    //generate 'searchRequestForArtifact' request object
    getSearchResponse("successcallForArtifact", _searchRequestForArtifact); 
    }
    if (Stores[2].length > 0) {
    //generate 'searchRequestForPerson' request object
    getSearchResponse("successcallForPer开发者_如何学Cson", _searchRequestForPerson);
    }
}

function successcallForArtifact(response)
{
    //show the results
}

function successcallForPerson(response)
{
    //show the results
}
}


If you need sequentially you will need to kick off each search only after one has returned. Currently you are making async calls, meaning it gets kicked off then continues with the code. Currently if the second call is simply faster the order will be off. You will either need to make a sync call or simply have the order enforced by calling the second search from the success function for the artifact.

If you are using JQuery which it seems you are you can set the async parameter to false which will force the order you want but it will slow the overall performance of your page. See this question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜