Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added support for ajax response pre-processors

  • Loading branch information...
commit 4abba5a3b113663ef0cf069a3bd3a40267d846ef 1 parent f637ca1
@juzna authored
Showing with 24 additions and 0 deletions.
  1. +9 −0 src/prototype/ajax/ajax.js
  2. +15 −0 src/prototype/ajax/request.js
View
9 src/prototype/ajax/ajax.js
@@ -44,5 +44,14 @@ var Ajax = {
getHeaderCreators: function() {
return Ajax._headerCreators;
+ },
+
+ /**
+ * List of pre-processors which will be executed on received ajax responses. It may change them
+ */
+ _responsePreProcessors: [],
+
+ addResponsePreProcessor: function(cb) {
+ Ajax._responsePreProcessors.push(cb);
}
};
View
15 src/prototype/ajax/request.js
@@ -305,6 +305,21 @@ Ajax.Request = Class.create(Ajax.Base, {
var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
if (state == 'Complete') {
+ // Execute pre-processors first
+ var shouldEnd = false;
+ Ajax._responsePreProcessors.each(function(cb) {
+ if(cb(this) === false) {
+ shouldEnd = true;
+ return $break;
+ }
+ }, this);
+ if(shouldEnd) {
+ // avoid memory leak in MSIE: clean up
+ this.transport.onreadystatechange = Prototype.emptyFunction;
+
+ return;
+ }
+
try {
this._complete = true;
(this.options['on' + response.status]
Please sign in to comment.
Something went wrong with that request. Please try again.