Reputation: 237
I am trying to return a json object from a function and use it as the below code, but it's not working. what wrong with it?
var x = [ "EditFileName" , "dosometing" ];
c_loadAjax.apply(this,x).done(function(json){
alert(json.error);
});
function c_loadAjax( post , option ){
$.ajax({
type:"POST",
url:"/includes/Ajax.php",
data:{post:post,option:option},
error:function(result){
return '{"error":"Error"}';
},
success:function(result){
return jQuery.parseJSON(result);
}
});
}
Upvotes: 1
Views: 4706
Reputation: 1440
Try with the return keyword
var x = [ "EditFileName" , "dosometing" ];
c_loadAjax.apply(this,x).done(function(json){
alert(json.error);
});
function c_loadAjax( post , option ){
return $.ajax({
type:"POST",
url:"/includes/Ajax.php",
data:{post:post,option:option},
error:function(result){
return '{"error":"Error"}';
},
success:function(result){
return jQuery.parseJSON(result);
}
});
}
Upvotes: 1