最白目
最白目

Reputation: 3654

how to get error message of failed ajax

I want to consume a webService which I get JSON Data from

    $.ajax({
    type: 'GET',
    contentType: 'application/json',
    dataType: 'JSON-P',
    //the url shows the correct JSON Data when I copy the URL in my browser
    url: 'http://url.com',
    success: function(data){
        console.log(data);
        alert(data);
    },
       error: function(xhr, testStatus, error){console.log("Error occured: "+error+" "+xhr+" "+testStatus)}
})

In Firefox, It calls back with the error function, but I dont know what the problem is, it would be great to know the error message but my approach doesnt work. thanks in advance

edit: In Chrome I get the following error:

Origin null is not allowed by Access-Control-Allow-Origin.

edit: It´s solved, the problem was indeed that json doesnt work cross site, and the data was not "jsonp-conform" (it had to set a function(json data...))arround the json data. This could be done by changing the url at the end "_&jsonp=successCallback. Sorry for bothering you

Upvotes: 4

Views: 3884

Answers (2)

anil shah
anil shah

Reputation: 3219

I think there was a JSON object syntax error. Check your JSON object syntax error with jsonlint.com.

Upvotes: 1

Thomas
Thomas

Reputation: 8859

Are you getting this error locally?

Try it on a server and if it doesn't work: XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin

Upvotes: 0

Related Questions