Ajax请求失败?

I am trying to retrieve json data from an api. It keeps failing, but when I look in the Net tab of Firebug I can see that the GET request executed and returned the correct data. Am I doing something wrong or does anyone have tips on how to debug this?

Edit: Have changed to dataType json and error status code is 0

Thanks

    $.ajax({
        url: 'http://localhost:55894/api/Test/All',
        data: {
            format: 'json'
        },
        error: function () {
            alert('Error');
        },
        dataType: 'jsonp',
        success: function (data) {
            alert('Ok');
        },
        type: 'GET'
    });

u can try this way:

$.ajax({
    type: 'GET',
    url: 'url api here',
    beforeSend: function() {
    },
    success: function(data) {

    },
    error: function(xhr) { // if error occured

    },
    complete: function() {

    },
    dataType: 'json'
});

JSON and JSONP are different. If you are using JSONP, the server side must be prepared to support it. Doesn't look like you are using JSONP.

So just change dataType to 'json', as you are "trying to retrieve json data".

From the info you provided the reason it is failing is because you dont have a cross domain access policy setup. Because you are using different ports to host the website and the API you are running into this issue. You can either setup a crossdomain.xml with the proper security settings or you can move both the API and the webserver to the same port.

Have a look at this for more info: http://en.wikipedia.org/wiki/Same-origin_policy