返回json对象的fron函数 [英] return json object fron function
本文介绍了返回json对象的fron函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从一个函数返回一个json对象,并将其用作以下代码,但是它不起作用.怎么了?
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);
}
});
}
推荐答案
尝试使用return关键字
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);
}
});
}
这篇关于返回json对象的fron函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文