服务器端代码
public function getAjax() {
$data = array('a'=>123);
$this->ajaxReturn($data,'json');
}
前端代码
$.ajax({
url : APP + '/Test/getAjax',
type : 'post',
dataType : "json",
data : {},
success : function (msg) {
console.log(msg);
},
error: function() {
console.log(arguments[1]);
}
});
服务器端返回的数据
{"a":123}
----------------------------------------------------------------------
同样在这个服务器上,不用tp框架,jQuery ajax请求后能执行success函数
$.ajax({
type: 'get',
async:false,
url: 'index.php?a=1',
data: {},
dataType: 'json',
success: function(data) {
alert(data['success']);
},
error:function(data) {
console.log(data);
console.log(arguments[1]);
}
});
服务端代码
<?php
echo json_encode(array("success"=>"fdfsd"));
页面请求后弹出 fdfsd
最佳答案