jQuery AJAX请求总是失败

时间:2015-01-06 13:51:12

标签: javascript jquery ajax json

当我这样做时,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}]

但它总是调用失败函数。

1 个答案:

答案 0 :(得分:0)

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');
        });