Sword 1.0b5 · A simple and friendly weblogging tool for academic environments created by Fingertips design & development.

 
 
 
 
 

Unexpected characters when using Prototype (AJAX)

TrackBack link: http://blog.markjuh.net/markjuh/trackback/2005/9/26/unexpected_characters_when_using_prototy

Published on 26 September 2005 at 13:27, updated on 2 October 2005 at 03:41.

In category Rails.

A little while back someone pointed me at the weird behaviour of my preview box when adding a comment. Somehow &_= was added to the end of the preview content.

It took me quite some time to figure out where it was coming from. I searched and searched, but couldn’t find the problem. I thought it wouldn’t be a Prototype bug, since Rails had been updated, but Prototype hadn’t changed.

So I asked around in #rubyonrails and Thomas Fuchs pointed me in the right direction.

It seemed changeset 2106 in Rails changed the way a Safari bug was tackled. It had been the case that Prototype added the &_= to the end of the POST data and ActionPack would strip this away again. But since another fix was found for this problem, there was no need for the &_= anymore.

So the following (line 213, or in the latest Edge Rails version line 476) should be removed from prototype.js:

if (parameters.length > 0) parameters += '&_=';

I had already discovered that removing the line fixed the problem, but it was good to find the reason why. And I’ve filed it as ticket 2258.

Comments

James on 4 January 2006 at 11:31.

Thank you. Thank you. Thank you.

It took me forever to figure out that the “&_=” was being passed – and a google search led me here. Then I removed the line from prototype.js and all is well.

Lindsey Simon on 25 February 2006 at 06:24.

It’s funny, because I was wondering if folks were using that bogus param to detect on the server side that the request was coming from an AJAX transaction as opposed to a user typed in browser request. Now that I know it’s more of a bugfix and should be removed I’m wondering how one ought to detect such a thing. And I don’t like the idea of having to add on a parameter every time I write a new Ajax.Request or whatever, but I also kinda don’t like the idea of making a wrapper object just to then call new Ajax.Request – but that’s what I’m leaning toward currently. Thanks for the post!

eric on 7 July 2006 at 18:36.

Thanks! This post is very helpful! the “&_=” thing seemed so wacky.

ps is there any reason you might want to keep this? IE solve the bug in Safari for users who have not upgraded?

Mark van Eijk on 14 August 2006 at 12:54.

Eric, it only has to do with the way Rails deals with the Safari bug. Totally independent from upgrading Safari.

And since the bug-handling in Rails has changed, the “&_=” thing is not necessary anymore.

New comments are disabled for this post