Skip to content

Instantly share code, notes, and snippets.

@jedireza jedireza/README.md
Last active Feb 25, 2016

Embed
What would you like to do?
ajaxStart and ajaxStop for ampersand-model using the ajaxConfig

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.