0
当我这样做AJAX调用jQuery的AJAX请求总是失败
var BASE_URL = "http://127.0.0.1:8000/index.php";
$.get(BASE_URL + "?r=category")
.done(function (data) {
alert('success');
})
.fail(function (error) {
alert('error');
});
这是服务器响应(使用Fiddler检查)
HTTP/1.1 200 OK
Date: Tue, 06 Jan 2015 13:46:19 GMT
Server: Apache/2.4.7 (Win32) PHP/5.5.8
X-Powered-By: PHP/5.5.8
X-Pagination-Total-Count: 3
X-Pagination-Page-Count: 1
X-Pagination-Current-Page: 1
X-Pagination-Per-Page: 20
Link: <http://127.0.0.1:8000/index.php?r=category%2Findex&page=1>; rel=self
Content-Length: 163
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8
[{"CaID":1,"Name":"Brot und Gebäck","ParentCaID":null},{"CaID":2,"Name":"Süßes und Salziges","ParentCaID":null},{"CaID":3,"Name":"Getränke","ParentCaID":null}]
但它总是会调用失败的函数。
你是否缺少从ajax.get传递page = 1? –
尝试$ .getJSON(),因为你的内容类型是'application/json' –
失败回调中的错误是什么?您的警报不是很有用的信息 – charlietfl