0
votes

I'm working on a project with Backbonejs (1.0.0) and I'm trying to fetch a model. Well, correct me if I'm wrong, but fetching a model means getting data from server and update model attributes. So, what I did:

The model:

var Lead = Backbone.Model.extend({
    idAttribute     : "project_id",
    defaults: {
        ws_qs       : 'toto'
    }
});

The action:

/* this.model comes from a collection, which has been fetched earlier. 
   So this.model contains correct data. I just want to refresh from the server. */
var tmpModel = this.model;
this.model.set({ws_qs : "youpi"}, {silent:true});

this.model.fetch({
  success : function (model) {
    // do something
  }
});

Fetch generates an XHR call with a correct url.

Some idea: in Chrome debuger, the XHR call response is empty, but opening xhr call url in a browser display correct JSON.

6 hours spending on that bug... anyone could help me? Thanks.

2
can you provide a small sample on jsfiddle.net - Dhiraj
Hey! I think that will be too complex :( There are many views, and collections involved... If you can provide me some "tracks" to look for that would be great. - Greg

2 Answers

1
votes

If Chrome debugger shows an empty response to the XHR, that's a strong indication that the server is misbehaving. Do you have access to the server side code? Perhaps the server code is looking at the request headers and responding incorrectly when the X-Requested-With header is XMLHttpRequest?

Try this command line curl -v -H "X-Requested-With: XMLHttpRequest" <url> and see what the response headers and body look like.

0
votes

I think maybe something wrong on the server side. check the response setting, if you want got json response, content-type should be "application/json". and it was "text/html" or something else in your case.