How to determine the resulting data type in backbone.js fetch ()?

Receiving data from the server returns me json data as a string data type , and not as an application / json type , as a result the collection is not updated.

I tried to provide the jquery.ajax contentType: "application / json" parameter for the fetch options, but it still doesn't work.

how can i make it work? can i send mimetype from server? if so, how?

I am using json_encode for the submitted data.

preloader.fetch({
        contentType:'application/json'
    });

preloader is an instance of my collection.

changing my template for subview was not detected, since I saved it outside the masterview $ el element , fixed it, and now I get the underscore.js error, which

str is null in

str.replace(/\\/g, '\\\\')     //at line 913

is it because the underlying application does not perceive it as a json object?

Request Headers

Connection  close
Content-Type    text/html
Date    Thu, 12 Apr 2012 13:00:58 GMT
Server  Apache
Transfer-Encoding   chunked
Vary    Accept-Encoding

Response headers has a line

Accept  application/json, text/javascript, */*; q=0.01

means it is json, then what is the problem?

+3
source share
1 answer

I think the contentType parameter for the request (your request).

Give it a try dataType:"json".

+5
source

All Articles