I want to get a value from JSON and use in a function, inside an Ajax request:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert('device ready');
function Hi(img_url){
alert('Hi, the img_url is '+img_url);
}
}
The ajax request:
$$.ajax({
type: "GET",
dataType: 'json',
url: target,
//Sucess
success: function(data){
var img_url = data.media.display_src;
Hi(img_url);
},
//Error
error: function(xhr,status){
alert("Error"+status+xhr);
console.log(xhr.response);
}
});
But the function Hi()
is always'undefined'...What's wrong?
Thanks