I am sending and ajax request (
backbone.model save) to my API built with ExpressJS. This is a cross domain request and everything works in that regards. The problem is that I receive a 200 response but a parsererror from the ajax call causing my error callback to always be called. I have looked into why this is happening and the following is what I have determined.
In the jQuery
ajaxConvert method, it receives two parameters. The first parameter is called
s and the second is the response from the request. The response is correct but inspecting what this method does I found out that the s parameter (which is an object) contains an attribute dataTypes. It uses this to determine how to convert the response correctly. The dataTypes attribute is an array and contains 3 items for me.
s.dataTypes = ["text", "http://localhost/1/user", "json"];
Since the second value in the datatypes array is the URL I sent the request to, the
ajaxConvert generates and parsererror and causes the error callback to be called for the request even though the request was successful (
200 OK) and sent the correct data.
I want to point out that normally the
s.dataTypes is like the following:
s.dataTypes = ["text", "json"];
I found this out inspecting another application I wrote which returns and parses the data correctly. (notice the omitted URL)
My question is rather does anyone know why this might be happening?
My web app stack is the following:
- Brunch.io for building HTML5 App
- Backbone.js + Chaplin.js for client side app written in coffee script.
- ExpressJS used to write API portion with MongoDB for the database.
Any help would be appreciated.