JQuery ajax call getting status code 0 "error"

I'm trying to call Petfinder.com to get a list of our pets. URL http://api.petfinder.com/shelter.getPets?key=xxxxx&id=CA1469&format=json

The url seems to return JSON. But when I try to make a call, I get an “error” and a status code of 0. I tried using jsonp, which results in a status of 200, but a parsing error. If I go to xml, I have the result of state 0 and "error".

 $.ajax({

         url: "http://api.petfinder.com/shelter.getPets?key=xxxx&id=CA1469&format=json",
         dataType: "json",
         type: "GET",
         success: function (data) {
             alert("hi");
         },
         error: function (jqXHR, exception) {
             if (jqXHR.status === 0) {
                 alert('Not connect.\n Verify Network.');
             } else if (jqXHR.status == 404) {
                 alert('Requested page not found. [404]');
             } else if (jqXHR.status == 500) {
                 alert('Internal Server Error [500].');
             } else if (exception === 'parsererror') {
                 alert('Requested JSON parse failed.');
             } else if (exception === 'timeout') {
                 alert('Time out error.');
             } else if (exception === 'abort') {
                 alert('Ajax request aborted.');
             } else {
                 alert('Uncaught Error.\n' + jqXHR.responseText);
             }

         }
     });
+5
source share
2 answers

You need to make sure that when the server sends you an error response, it will also send the corresponding CORS headers along with it.

, JavaScript- , , .

+2

CORS XSS. - - AJAX.

+1

All Articles