jQuery AJAX 请求总是失败

jQuery AJAX request always fails

本文关键字:失败 请求 AJAX jQuery      更新时间:2023-09-26

当我做这个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}]

但它总是调用 fail 函数。

var BASE_URL =  "http://127.0.0.1:8000/index.php";
$.get(BASE_URL + "?r=category")
        .done(function (data) {
            alert('success');
        })
        .fail(function (error) {
            console.log(error);//to show what error happended
            alert('error');
        });