Reputation: 28
I'm new to backbone, and I've been fairly successful with model and view implementation. Now I am looking into building a RESTful back-end to experiment with this aspect of backbone. So, I've created this simple client to test requests and responses. However, I keep receiving this error:
A "url" property or function must be specified
Seems to me a client problem, but perhaps it is on the server side. Can anyone explain why I might be getting this error, of if this setup is wrong, why?
var m_Blog = Backbone.Model.extend({
defaults: {
url:'/lib',
title: null,
date: null,
content: null,
keywords: null,
}
});
var a = new m_Blog({title:'t', date:'d', content:'c', keywords:'w'});
a.save({
success: function(model, response) {
alert('Success' + response.getResponseHeader());
},
fail: function(model, response) {
alert('Fail' + response.getResponseHeader());
}
});
I've also tried a simple save call since, I'm really not sure yet if the above works:
a.save();
Upvotes: 0
Views: 219
Reputation: 76
I believe the attribute is actually called "urlRoot". Have you tried changing your defaults to this?
defaults: {
urlRoot:'/lib',
title: null,
date: null,
content: null,
keywords: null,
}
url is the function name on the model to get the urlRoot (ie. model.url()).
If that doesn't work, you could also try setting the urlRoot this way although I'm pretty sure it's doing the same thing as above :-).
var m_Blog = Backbone.Model.extend({
defaults: {
title: null,
date: null,
content: null,
keywords: null,
},
urlRoot: '/lib'
});
Upvotes: 1