I use backbone-tastypie, but I have the most difficult time to get it to work correctly. In Tastypie I use ApiKeyAuthentication for my resources, so every ajax request, I have to add apikey and username to the end of the request or send additional headers that are added to the username and api key.
I am trying to remove a view and its model using a trunk with the following code:
removeItem: function() {
this.model.destroy({wait: true, success: function() {
console.log("success");
}, error: function() {
console.log("error");
}});
},
After executing the function, the browser tries to execute the GET request at the following URL:
:8000/api/v1/update/2/
api_key , URL- . , Backbone.oldSync GET. , username/api ?
, api http-, backbone-tastypie:
if ( !resp && ( xhr.status === 201 || xhr.status === 202 || xhr.status === 204 ) ) { // 201 CREATED, 202 ACCEPTED or 204 NO CONTENT; response null or empty.
var location = xhr.getResponseHeader( 'Location' ) || model.id;
return $.ajax( {
url: location + "?" + "username=" + window.app.settings.credentials.username + "&api_key=" + window.app.settings.credentials.api_key,
success: dfd.resolve,
error: dfd.reject,
});
}