Take the tour ×

After spending hours searching for a solution, I'm finally posting the question here guys. Let me know my degree of stupidity :).

Here's the code:

Model and collection:
var app = app || {};
var metricsModel = Backbone.Model.extend({});
var MetricsList = Backbone.Collection.extend({
  sync: function(method, collections, options) {
    options.dataType = "jsonp";
    return Backbone.sync(method, collections, options);

app.CommitmentView = Backbone.View.extend({
    app.metrics = new MetricsList();
    app.metrics.bind("change", this.render, this);
      success: function(collection,response) {
        console.log("fetch successful" + response);
      error: function(collection,response) {
        console.log("error" + JSON.stringify(response));

Result: error{"readyState":4,"status":200,"statusText":"success"}.

The error callback is getting called always. I don't have much control over the backend. Just made sure the following checks are done:

Server responds with the correct JSON - An array of JSON objects. Tested on FF and Chrome. JSON keys are strings.

How can I debug this further? Let me know please.

share|improve this question
Can you check the HTTP request, error code that is sent ? With Chrome or Sagari, you can see that with the Web Inspector (developers.google.com/chrome-developer-tools/docs/overview). –  Laurent Perrin Dec 19 '12 at 14:55
@LaurentPerrin isn't it mentioned in the question? "readyState":4,"status":200,"statusText":"success" –  fencliff Dec 19 '12 at 15:56
The value passed to the callback suggests that the query is OK, but that's not the actual HTTP request. –  Laurent Perrin Dec 19 '12 at 16:16
Is it your server, or an external one? Remember, it needs to actually support JSONP for this to work -- it shouldn't return just raw JSON, it has to return JSON wrapped in a Javascript function. –  McGarnagle Dec 19 '12 at 19:29
@dbaseman The server is an external one but I know those people, so they will be able to tweak it. The server does return raw JSON. I'll ask these guys to return JSON within a javascript function. Will post here if that works. Thanks –  Pradeep Banavara Dec 20 '12 at 3:02
show 1 more comment

1 Answer

So it happens that the backend was returning a json object. The REST framework used in the backend is so flexible that all I had to do was replace json with jsonp in the URL.

Old URL : http:///format/json New URL : http:///format/jsonp

Here's the REST Framework https://github.com/philsturgeon/codeigniter-restserver

Thanks @dbaseman for your suggestion/comment

share|improve this answer
add comment

Your Answer


