this is my logout click event:
logoutClicked: (event) ->
event.preventDefault()
console.log 'userPanel.logoutClicked -> event', event
console.info App.session
App.session.destroy
wait: true
success: (model, res) ->
console.log 'session.destroy.success -> model/res', model, res
error: (model, res) ->
console.log 'session.destroy.error -> model/res', model, res
this is my session model:
class App.Model.Session extends Backbone.Model
initialize: ->
console.log 'Session.init'
urlRoot: '/session'
and this is my slim backend route:
$app->delete('/session', function () {
session_unset();
exit(true);
});
When i trigger the logoutClicked event all is working fine, but i can’t see any server communication (no DELETE or GET to /session…) through my firebug..
Firebug output:
userPanel.logoutClicked -> event Object { originalEvent=Event click, type="click", timeStamp=18807379, altri elementi...}
Session { cid="c1", attributes={...}, _changing=false, altri elementi...}
session.destroy.success -> model/res Session { cid="c1", attributes={...}, _changing=false, altri elementi...} null
as u can see no DELETE request fired… and i receive a null res from my session.destroy success callback…
I’m new on Backbone, any suggestion? Maybe i have to setup Backbone.sync?
If you call Model.destroy(…) on a new Model (which Model.isNew() === true). .destroy(…) won’t do anything.
Reference:
One way to “force” destroy to be called is to manually set Model’s ID to be not NULL, like…
However, when you retrieve App.Session, its ID should already be set to the session ID. In that case, when retrieving a session from the server, you may want to do this step manually.
Side Note
If you want to call your ID attribute as
sessionIDinstead of just id, you can also override the defaultidAttributeonBackbone.Model.