Reputation: 17
Here's the code
This is model
var TodoItem = Backbone.Model.extend({
url: 'list.php',
DeleteTabItem: function (child, parent) {
jQuery.ajax({
url: 'delete.php',
});
}
});
This is view
var TodoView = Backbone.View.extend({
el: '.entry-title',
template: _.template(''),
KeyPressEvent: function () {
this.model.DeleteTabItem();
}
});
Is this correct way of sending ajax request.
Thanks in Advance
Upvotes: 1
Views: 3072
Reputation: 6938
In backbone model, instead of url,
use : urlRoot
: "yoururl",
Backbone.Model.extend({
urlRoot: 'list.php'
});
url
would be used in collections
For sending data through view :
this.model.save(sendData, { success, error });
where sendData = { data preferably in json }
You will have to bind the model with your view like :
var todoView = var TodoView(model:TodoItem);
Upvotes: 2
Reputation: 66
In Backbone world, we usually use multiple models and collection instead of handle data directly via JQuery AJAX function.
So you just need to persist your values into model or collections, and execute correspond actions, like fetch(), save(), destroy()...They have default request type.
As for your code, you still can use new function "DeleteTabItem", but inside, the better way is call some model or collection's destroy action.
Upvotes: 1