aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts')
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/prototype.js32
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);
}