Because the default behave of jquery ajax is async mode, you Can't directly get the response.
At Least, You have two choice:
- pass the func as parameter into "callme":
function callMe(callback) {
$.ajax({
url: "someJson.php",
type: "GET",
dataType: 'json',
success: function(response){
callback(response);
}
});
}
function dealResponse(response) {
// do something with response
}
callMe(dealResponse);
- use sync mode ajax, and use your code directly get response and deal with it. but if you go this way, you script will block and may temporarily lock the browser when ajax request start, until the request end.
function callMe() {
var ret;
$.ajax({
url: "someJson.php",
type: "GET",
async
dataType: 'json',
success: function(response){
ret = response;
}
});
retun ret;
}
var jsonResponse = callMe();
Hope these could help you :)