Also see the discussion about global ajax settings:
Add support for a global ajaxConfig Thus far we've just gone for having a base model and base collection in every project.
Also see the discussion about global ajax settings:
Add support for a global ajaxConfig Thus far we've just gone for having a base model and base collection in every project.
/* global $ */ | |
var AmpersandModel = require('ampersand-model'); | |
var ajaxStart = function () { | |
$('.ajax-spinner').show(); | |
}; | |
var ajaxStop = function () { | |
$('.ajax-spinner').hide(); | |
}; | |
var BaseModel = AmpersandModel.extend({ | |
ajaxConfig: { | |
xhrFields: { | |
onreadystatechange: function (xhr) { | |
if (this.readyState === 4) { | |
ajaxStop(); | |
} | |
}, | |
ontimeout: function () { | |
ajaxStop(); | |
}, | |
onabort: function () { | |
ajaxStop(); | |
} | |
}, | |
beforeSend: function (xhr) { | |
ajaxStart(); | |
} | |
} | |
}); | |
module.exports = BaseModel; |