I am newbie to Backbone. I am trying to fetch data from json
in backbone.But its not getting the data. going in error function when trying to fetch the data.Here's my code:
var Item = Backbone.Model.extend();
var List = Backbone.Collection.extend({
model: Item,
url: "form.json",
parse: function(response) {
return response.results;
},
sync: function(method, model, options) {
var that = this;
var params = _.extend({
type: 'GET',
dataType: 'jsonp',
url: that.url,
processData: false
}, options);
return $.ajax(params);
}
});
var ListView = Backbone.View.extend({
el: $('.deep-div'),
events: {
'click button#add': 'getPost'
},
initialize: function() {
_.bindAll(this, 'getPost');
this.collection = new List();
this.getPost();
},
getPost: function() {
var that = this;
this.collection.fetch({
success: function() {
console.log(that.collection.toJSON());
},
error: function() {
console.log('Failed to fetch!');
}
});
}
});
var listView = new ListView();
And my json
is
{
"status": "SUCCESS",
"statusMessage": "",
"payload": [
{
"type": "text",
"label": "Name",
"currentValue": " ",
"isRequired": "true"
},
{
"type": "Date",
"label": "DOB",
"currentValue": " ",
"isRequired": "true"
}
]
}