I’m trying to retrieve account information for multiple accounts transforming the XML data to JSONP. The problem is that all the functions get kicked off at the same time and the results get populated as the GET request comes in. Here is the reduced code:
$(document).ready(function() {
GetInfo("user1","pass2");
GetInfo("user2","pass4");
GetInfo("user3","pass6");
});
function GetInfo(login, passwd)
{
login = escape(login);
login = login.replace("+","%2b");
passwd = escape(passwd);
passwd = passwd.replace("+","%2b");
var url = "...";
var yql = 'https://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20xml%20where%20url=%27' + escape(url) + '%27&format=json&callback=cbfunc'
$.ajax({
type:"GET",
dataType:"jsonp",
url: yql,
});
}
function cbfunc(data)
{
$('#container').html(data.query.results);
}
This code returns user1,user2, user3 in random order. Ideally, i’d want each call to be blocking and complete before it goes to the next GetInfo call. This is my first time working with JSONP so if there are any tricks i’m missing, i’d appreciate pointers. Thanks
You can use jquery message queuing. http://benalman.com/code/projects/jquery-message-queuing/docs/files/jquery-ba-jqmq-js.html