1.
test.user=Backbone.Model.extend({
initialize: function(options) {
this.options=options;
//this.fetch();
},
url: function() {
switch (this.options.mode){
case 0:{return this.options.host+'user/id/'+this.options.selector;}
}
},
parse: function(response) {
switch (this.options.mode){
case 0:{
var entry=new Object();
entry=response[0];
return entry;
}
}
}
});
2. в контроллере или функции test.user.fetch().done(function(response){'тут смотришь ответ от сервера'})
3. Или
Admin.SessionModel=Backbone.Model.extend({
urlRoot:'check',
initialize: function () {
var that = this;
// Hook into jquery
// Use withCredentials to send the server cookies
// The server must allow this through response headers
$.ajaxPrefilter(function( options, originalOptions, jqXHR) {
options.xhrFields = {
withCredentials: true
};
});
},
login: function(creds) {
// Do a POST to /api/session and send the serialized form creds
var that = this;
this.save(creds, {
success: function (model, resp) {
if (resp.success == false) {
alert(resp.message);
}
that.unset('password');
that.set(resp.data);
iApp.trigger("login:action:success");
iApp.radio.trigger('login_form:close');
},
error:function(model,resp){
iApp.trigger("login:action:error");
console.log('error')
}
});
},
logout: function() {
// Do a DELETE to /api/session and clear the client side data
var that = this;
this.destroy({
success: function (model, resp) {
model.clear({silent:true});
$.ajax({url:'logout'}).done(function(){
iApp.trigger("logout:action");
console.log('App log out')
})
// Set auth to false to trigger a change:logged_in event
// The server also returns a new csrf token so that
// the user can relogin without refreshing the page
that.set({logged_in: false});
}
});
},
getAuth: function(callback) {
// getAuth is wrapped around our router
// before we start any routers let us see if the user is valid
var that=this;
this.fetch().done(function (data) {
that.set('status', data.status);
//console.log(data)
return data;
});
}
})
4. или если надо пояснения пиши в личку