I'm trying to get the most basic thing running in Backbone.js but somehow fail. The code I've produced for saving a url model into the server.
urlToAdd.set({url: urlBody.value, tags:tagsToAdd});
urlToAdd.save({
success:function(){
console.log('it works');
}
});
It successfully sends the data to my php page however I can not get successevent to work. Where am I doing wrong? I've carefully observed and couldn't find anything.
Here is my model definition: (Unfortunately since I am backbone noob I've applied this by checking a tutorial and I have no idea if the codes in url function are necessary
var URLWithTags=Backbone.Model.extend({
initialize:function(){
console.log('URL object has been initialized');
},
defaults:{
url:'not defined',
tags:[]
},
validate:function(attributes){
//console.log(attributes.tags[0].length);
/*if(attributes.tags[0].length<1)
return "You should create at least one tag";*/
},
urlRoot:'/URLTags/manage.php',
url:function(){
var base = this.urlRoot || (this.collection && this.collection.url) || "/";
console.log("Base has been produced");
if(this.isNew())
return base;
return base+"?id="+encodeURIComponent(this.id);
},
});