Stephan Ahlf
Stephan Ahlf

Reputation: 3497

Backbone model fetch error

I try to load simple JSON object from static json file, but fetch is triggering error handler.

        this.model.fetch({ 
            error: function(){ 
                console.log(arguments); 
            }
        });

Then arguments[1].state is 200 and request looks good.

This model is

Backbone.Model.extend({ 
defaults: {
  title: "no title loaded",
  body : "no body loaded",
  parm1 : "no parm 1",
  parm2 : "no parm 2"
},
url : 'api/data.json'
});

data.json

{
title: "My New Demo", 
    body: "This is my first demo text!"
}

Where can i find error details ?

Upvotes: 0

Views: 1213

Answers (2)

jcreamer898
jcreamer898

Reputation: 8189

Make sure that your server is using 'application/json' as the mimeType. Backbone uses $.ajax under the covers and it might not understand the .json file.

Upvotes: 0

Ven
Ven

Reputation: 19039

JSON keys must be quoted.

{
    "title": "My New Demo", 
    "body": "This is my first demo text!"
}

Upvotes: 1

Related Questions