Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6681 (closed defect: untested)

Opened 2 years ago

Last modified 9 months ago

[PATCH] Patch to Prototype Ajax.Request to solve Opera bug

Reported by: baggy Assigned to: sam
Priority: normal Milestone:
Component: Prototype Version:
Severity: normal Keywords: Prototype, Opera buglet
Cc: chewi

Description

In a bug I reported last week (can't locate ticket no) I pointed out that Prototype's Ajax.Request object doesn't work asynchronously...

I've tracked this down to onStateChange, where the "this" is the "arguments array" rather than what is expected (the Request object) when called asynchronously (something to do with the bind() method)

replacing this with:

onStateChange: function() {

if( this.length ){

var readyState = this[0].transport.readyState;

if (readyState > 1) this[0].respondToReadyState(readyState);

} else {

var readyState = this.transport.readyState;

if (readyState > 1) this.respondToReadyState(readyState);

}

},

Solves the problem and Opera is happy again.... This has been checked on IE/Firefox/Opera.

Change History

11/26/06 21:03:09 changed by madrobby

  • owner changed from Rails to sam.
  • priority changed from high to normal.
  • component changed from script.aculo.us to Prototype.
  • severity changed from major to normal.

(follow-up: ↓ 5 ) 12/06/06 17:56:17 changed by chewi

This seems to be more serious in 1.5.0_rc2. The above replacement has to be made but line 780 also has to be changed. I changed this...

setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);

To this...

setTimeout(function() { (this.length ? this[0] : this).respondToReadyState(1) }.bind(this), 10);

That was enough to allow the request to be made but Ajax.Updater still failed to update an element with the response. I'm not sure what's going on but I think this is definitely a problem.

12/06/06 17:58:42 changed by chewi

  • cc set to chewi@aura-online.co.uk.

12/06/06 18:05:36 changed by chewi

  • cc changed from chewi@aura-online.co.uk to chewi.

(in reply to: ↑ 2 ) 12/24/06 17:45:19 changed by SamaelS

The this.length trick doesn't work at all with my opera 9.1/win. But I've managed to find a work around that works fine with IE, FF and Opera :

Replace: setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);

by: var self = this; setTimeout(function() { self.respondToReadyState(1) }, 10);

I guess Opera 9 does not understand correctly the bind function ...

10/24/07 21:48:19 changed by mislav

  • status changed from new to closed.
  • resolution set to untested.