Forum Moderators: open

Message Too Old, No Replies

Safari - window.location changing from GET to POST

         

Nutter

1:46 am on May 15, 2008 (gmt 0)

10+ Year Member



I've got a bit of JS code that calls window.location to a PHP script with a query string. Something like script.php?a=123&b=234. That sort of thing.

But when it gets to script.php the variables are part of the POST set instead of the GET set like they should be. This only happens in Safari. FF and IE work correctly.

Any thoughts on why this is happening?

httpwebwitch

3:56 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that's bizarre. I've never heard of this happening before; it would break gazillions of web pages.
What version of Safari are you running? which OS?

Nutter

4:17 pm on May 15, 2008 (gmt 0)

10+ Year Member



Safari on Vista. I downloaded Safari yesterday so it's whatever the most recent is. But I've been getting reports of this particular script not working for a while. It's just that yesterday I finally traced it back to just users running Safari.

And I can rewrite the backend to use the post data, but that doesn't make sense to do if I don't have to.

Could it be some type of encoding issue? I made sure that the & was &, but is there an entity for ? as well that I should be using?

httpwebwitch

4:54 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



and on the back end - are you reading the collections with PHP $_GET or something similar?

I did read about some problems with Safari's XHR implementation, that it doesn't handle POST properly... that seems like an unrelated issue. Or is it?

does the URL of the destination page (once you land on it, ie in the address bar) show the querystring? has it been stripped or truncated?

Also confirm if there are any server-side redirects happening between the window.location execution and the request for the destination page; handling scripts, stuff in the .htaccess, anything that would interfere with going normally from one page to another.

does this also happen when you do a plain <a href="script.php?a=1&b=2"> ?

I don't have Safari installed, so I'm just guessing

a print_r() of all your $_SERVER, $_GET and $_POST variables might also shed some light on what's going on.

Nutter

5:18 pm on May 15, 2008 (gmt 0)

10+ Year Member



a print_r() of all your $_SERVER, $_GET and $_POST variables might also shed some light on what's going on.

That's actually how I finally figured out what was going on. Anything that should have been in $_GET was actually in $_POST. And I can use $_REQUEST to pick up both but the way the PHP is written it uses the request method as part of the decision tree, although I could rewrite the script if I really have to. It just seems that I shouldn't have to if it's just some type of simple error on my part.

The window.location call is going to script.php?a=1&b=2. Only script.php shows up in the address bar. When I do the print_r is shows $_POST['a']=1 and $_POST['b']=2.

And I've Googled just about every combination of terms I can think of to try and find someone else that has something similar happen. No luck though.

[edited by: Nutter at 5:18 pm (utc) on May 15, 2008]

Nutter

2:39 am on May 16, 2008 (gmt 0)

10+ Year Member



Ok, bonehead error :)

The image that was being used to trigger the JS onclick was <input type="image"> and I forgot to put a return false; after the window.location call so the form was being submitted which was a post request. Similar variable names so I just missed the one variable that's different between the form submitting and the javascript call. Same script, different action.

That's about 3 hours of searching and trying different things for what turned out to be 13 characters.