How to get failed ajax error message

I want to use webService, which gets 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 don’t know what the problem is, it would be great to know the error message, but my approach does not work. thanks in advance

edit: In Chrome, I get the following error:

The origin of null is not allowed by Access-Control-Allow-Origin.

edit: it is solved, the problem is that json does not work with the cross site and the data was not "jsonp-conform" (he needed to install the function (json data ...)) arround json data, This can be done by changing The URL at the end is "_ & jsonp = successCallback. Sorry to bother you.

+4
source share
2 answers

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

+1
source

Are you getting this error locally?

Try it on the server and if that doesn't work: XmlHttpRequest error: Null origin is not allowed Access-Control-Allow-Origin

0
source

Source: https://habr.com/ru/post/1416133/


All Articles