I have a Json get request that works perfectly when I use CURL to send it over php , but when I try to do the same thing with getJSON (which is the requirement), all I get back is status is error when I use the code below. How can I know exactly what the error is ? I dont know if I am sending the request with wrong parameters of if its a time out, or what it could be. Thanks
$.getJSON(url, function(data,status,xhr) {
if (status == "success"){
alert ("got the data"+data);
}else if (status == "timeout"){
alert("Something is wrong with the connection");
}else if (status == "error" || status == "parsererror" ){
alert("An error occured");
}else{
alert("datatosend did not change");
}
})
the answer was that although I was on the same domain I was not putting https on the url to get which is what my site was using.
thanks
How can I know exactly what the error is
An answer to that at least :
$.getJSON(url, function(data,status,xhr) {
alert ("got the data"+data);
}).fail(function(a,b,c) {
console.log(a,b,c);
});
I'm guessing CORS error and same-origin policy as it works with cURL, and if that's case and it's not your server there's not much you can do other than go back to using cURL, which to me sounds like a much better approach to begin with.