following javascript jquery and using eval , I still can't get jquery to read data asynchronously.
data1=[1,2,3,4]
Note: I included async: true in the example below to show the difference
Below example returns "null"
$(document).ready(function(){
var myArray=[];
myArray=getValues();
alert(myArray);
function getValues(){
var result=null;
$.ajax({
url: 'data1.html',
type: 'get',
dataType: 'json',
cache: false,
success: function(data) {result = data;},
async:true,
});
return result;
};
})
and below the example works fine and gives the result in the ie array [1,2,3,4]
$(document).ready(function(){
var myArray=[];
myArray=getValues();
alert(myArray);
function getValues(){
var result=null;
$.ajax({
url: 'data1.html',
type: 'get',
dataType: 'json',
cache: false,
success: function(data) {result = data;},
async:false,
});
return result;
};
})
can anyone explain how to get the results asynchronously Thanks
source
share