Debug backbone collection fetch fails with no models loaded
This situation happened to be from time to time over the last few years and I still struggle with it every time so I decided to write down my troubleshooting steps and solutions
Step 1 - See what is the HTTP error code. If it is not 200 or 2XX, then you know already what is wrong, the answer should be a HTTP success code.
Step 2 - If your HTTP response code is success but you still get no data loaded, make sure you have a error handler to your fetch() function. Like this :
Step 3 - Make sure your Content-Type matches your jquery response handling. For example Content-Type: application/json would result in jquery automatically parsing the request. If your Content-Type is text/plain, then you are responsible for parsing the JSON. If your Content-Type is applicaton/json, make sure you dont get a "parsererror".
Step 4 - Verify that your JSON returned has a valid syntax. This could result in a silent error. One method is to paste your json in a JSON validator like http://jsonlint.com. Another way to verify is to put a breakpoint at
jquery.js
ajax: function( url, options ) {
(...)
isSuccess = ajaxConvert( s, response );
statusText = isSuccess.state;
An invalid JSON syntax would result in isSuccess being set to false.
Recent Comments