It seems very inconvenient that jQuery’s $.getJSON silently fails when the data returned is not valid JSON. Why was this implemented with silent failure? What is the easiest way to perform getJSON with better failure behavior (e.g. throw an exception, console.log(), or whatever)?
It seems very inconvenient that jQuery’s $.getJSON silently fails when the data returned is
Share
you can use
If you want to see the cause of the error, use the full version
If your JSON is not well-formed, you will see something like
If the URL is wrong, you will see something like
If you are trying to get JSON from another domain, violating the Same-origin policy, this approach returns an empty message. Note that you can work around the Same-origin policy by using JSONP (which has it’s limitations) or the preferred method of Cross-origin Resource Sharing (CORS).