这是调用 Controller 中函数的 Jquery。但它无法读取 Json_encoded 对象。我正在使用代码点火器。为什么?
$(this).ajaxSubmit({
type : "POST",
url: '../index.php/user/signin', // target element(s) to be updated with server response
cache : false,
dataType:'json',
success : function(data){
data = $.trim(data);
alert(data);
var obj = jQuery.parseJSON(data);
alert(obj.Condition);
},
error: function(){
}
Controller
$arr = array('Condition' => $condition, 'Message' => $msg);
// header('Content-Type: application/json');
echo json_encode($arr);
最佳答案
尝试使用eval
代替parseJSON
在js中:
$(this).ajaxSubmit({
type : "POST",
url: '../index.php/user/signin', // target element(s) to be updated with server response
cache : false,
dataType:'json',
success : function(data){
data = $.trim(data);
alert(data);
var obj = eval('(' + data+ ')');
alert(obj.Condition);
},
error: function(){
}
我还认为没有必要使用 $.trim 来处理响应数据
关于javascript - javascript Codeigniter 中的 Json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18822625/