var query1 = urlencode($('input[name="searchTerm1"]').val()); //user1
var query2 = urlencode($('input[name="searchTerm2"]').val()); //user1
var rpp = 20; //number of tweets to retrieve out
var c=0;
var f1=new Array();
var f2=new Array();
var common=new Array();
$.getJSON('http://twitter.com/followers/ids.json?screen_name='+ query1 + '&callback=?',
function(data) {
f1=data;
$('#content').append('p'+f1[0]+'p');//this one is coming
});
$.getJSON('http://twitter.com/followers/ids.json?screen_name='+ query2 + '&callback=?',
function(data1) {
f2=data1;
});
$('#content').append('p'+f1[0]+'p');//this one is not coming...its showing Undefined
})
In this code if u see clearly i have identified using // two append statements
one of them is working and outputting the number in the array
but the other one is outputting Undefined
i have defined the arrays so it should take the values but wat actually happens is that the array become inaccessible outside the $.getJSON function.
Any help will be appreciated.
Thank You
@anand, $.getJSON() retrieves JSON data in an asynchronous manner. The purpose of you callback functions is to perform work once the JSON has been received from the asynchronous request. I’ll simplify your example some:
Please check out the comments regarding your calls to append(). Hope this helps!