diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-27 17:40:00 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-27 17:40:00 +0000 |
commit | 938a8fea27a5271403edc6a3e6ab76dda15d9a5b (patch) | |
tree | 11800e755ab7278f06859c5dbdd25cc3841e8da0 /actionpack/lib/action_view/helpers/javascripts | |
parent | 05ef7898bd42970a45a6727b1cf44338982ab2c6 (diff) | |
download | rails-938a8fea27a5271403edc6a3e6ab76dda15d9a5b.tar.gz rails-938a8fea27a5271403edc6a3e6ab76dda15d9a5b.tar.bz2 rails-938a8fea27a5271403edc6a3e6ab76dda15d9a5b.zip |
Added support for graceful error handling of Ajax calls #1217 [Jamis Buck/Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1545 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/prototype.js | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js index eefb6e82b8..bba61b91a0 100644 --- a/actionpack/lib/action_view/helpers/javascripts/prototype.js +++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js @@ -236,14 +236,24 @@ Ajax.Request.prototype = (new Ajax.Base()).extend({ respondToReadyState: function(readyState) { var event = Ajax.Request.Events[readyState]; - (this.options['on' + event] || Prototype.emptyFunction)(this.transport); + + if (event == 'Complete' && this.transport.status != 200) + (this.options['on' + this.transport.status] || + this.options.onFailure || + Prototype.emptyFunction)(this.transport); + + (this.options['on' + event] || Prototype.emptyFunction)(this.transport); } }); Ajax.Updater = Class.create(); Ajax.Updater.prototype = (new Ajax.Base()).extend({ initialize: function(container, url, options) { - this.container = $(container); + this.containers = { + success: container.success ? $(container.success) : $(container), + failure: container.failure ? $(container.failure) : null + } + this.setOptions(options); if (this.options.asynchronous) { @@ -258,16 +268,20 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({ }, updateContent: function() { - if (this.request.transport.status == 200) { + var receiver = + (this.request.transport.status == 200) ? + this.containers.success : this.containers.failure; + + if (receiver) { if (this.options.insertion) { - new this.options.insertion(this.container, - this.request.transport.responseText); + new this.options.insertion(receiver, + this.request.transport.responseText); } else { - this.container.innerHTML = this.request.transport.responseText; + receiver.innerHTML = this.request.transport.responseText; } - } - - if (this.onComplete) { + } + + if (this.request.transport.status == 200 && this.onComplete) { setTimeout((function() {this.onComplete( this.request.transport)}).bind(this), 10); } |