{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"user":{"avatar_url":"https://secure.gravatar.com/avatar/94cb827736e36e0f6343e9640e72fec7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"94cb827736e36e0f6343e9640e72fec7","url":"https://api.github.com/users/vlucas","login":"vlucas","id":187},"milestone":null,"labels":[],"assignee":null,"updated_at":"2011-11-10T23:15:58Z","comments":3,"closed_at":null,"url":"https://api.github.com/repos/documentcloud/backbone/issues/741","body":"I am trying to implement a global AJAX loading indicator in a new Backbone project, and I was not able to find any built-in events to hook into for displaying and hiding a loading indicator.\r\n\r\nIt would be helpful if Backbone fired events for each of: 'ajax:start', 'ajax:stop', 'ajax:error', 'ajax:success' when using the native Collection.fetch(), etc. methods.","html_url":"https://github.com/documentcloud/backbone/issues/741","title":"Global events for ajax start/stop/error/success","number":741,"id":2203748,"created_at":"2011-11-10T22:32:07Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/fc40b1fe79ea6b10825141d86f767354?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"fc40b1fe79ea6b10825141d86f767354","url":"https://api.github.com/users/yuchi","login":"yuchi","id":646609},"updated_at":"2011-11-10T23:15:58Z","url":"https://api.github.com/repos/documentcloud/backbone/issues/comments/2702773","body":"That's true, but if you want to hook into all the ajax requests you need in the models and collection the `ajax:*` events @vlucas talks about. In such a way you can bind to them inside the model/collection's view and act.\r\n\r\n```coffeescript\r\nBBSync = Backbone.sync\r\nBackbone.sync = (method, model, options) ->\r\n  model.trigger 'ajax:start'\r\n  xhr = BBSync.call this, method, model, options\r\n  xhr.on 'complete', -> model.trigger 'ajax:end'\r\n  return xhr\r\n```\r\n\r\nThis can be a little too simplicistic, but should do the job.\r\n\r\nPS: I'm not sure how to bind to 'complete' event in jQuery, they moved the APIs a little too much :(","id":2702773,"created_at":"2011-11-10T23:15:58Z"}}