Skip to content

Instantly share code, notes, and snippets.

@d13
Forked from jedireza/README.md
Created February 25, 2016 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d13/eaf4f1f5063c7f35c11d to your computer and use it in GitHub Desktop.
Save d13/eaf4f1f5063c7f35c11d to your computer and use it in GitHub Desktop.
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