$.getJSON scope problem
Question
$.getJSON('http://twitter.com/followers/ids.json?screen_name=' + query1 + '&callback=?', function (data) {
console.log('JSON data string 1 is: ' + data);
$.getJSON('http://twitter.com/followers/ids.json?screen_name=' + query2 + '&callback=?', function (data1) {
console.log('JSON data string 2 is: ' + data1);
f2 = data1;
f1 = data;
for (var i = 0; i < f1.length; i++) {
for (var j = 0; j < f2.length; j++) {
if (f1[i] == f2[j]) { //console.log("Adding f1[i]");
common.push(f1[i]);
}
}
}
for (var d = 0; d < common.length; d++) {
$.getJSON('http://twitter.com/users/show.xml?user_id=' + common[d] + '&callback=?', function (data2) {
$('#content').append('<>img width="50" height="50" src=' + data2.profile_image_url + '><
href="http://www.twitter.com/' + data2.screen_name + '">' + data2.name + '</></>');
});
}
});
});
in this code basically im getting an array(common[]) that contains all the common followers between two twitter users
but the third $.getJSON call doesnt seem to responding at all
Am i doing something wrong
Any help will be appreciated
Thank You
Solution 2
got it working...the problem was that the url had show.xml ...i just changed it to show.json and it started working
OTHER TIPS
setup a global AJAX error event handler like so, and you can then inspect the error. remember if an error occurs within the context of a jQuery AJAX request then nothing happens outside of the error function. if you are using the $.getJSON method then you must set up the error handler in the $.ajaxSetup method.
$.ajaxSetup({
error: function(xhr, status, e) {
console.log(xhr, status, e);
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow