I searched for a related topic in jQuery, but I didn't see any method to solve my problem.
$(document).ready(function(){
$("#inputForm").submit(function(event){
$(":text").each(function() {
var inputText = $(this).val();
var userList = [];
var weblink = 'http://test.com';
// problem is from here.
$.getJSON(weblink, function(data){
alert(weblink); // this statement doesn't show up
$.each(data, function(entryIndex, entry){
userList.push(entry['from_user']);
});
});
alert(userList);
});
});
});
There are 3 problems here:
- Why doesn't the first alert('weblink') doesn't show up?
- Why this code can't get the json data from website?
- The goal of this code is to get the from_user tag from json file and store into userList array.
The variables in "$.each(data, function(entryIndex, entry){" statement, the function have two input parameters one is entryIndex and other is entry. I am wondering what these parameters are for and how to use them?.
Can anyone help me solve this problem. I have been stock in here for one day. Thank you very much.