View Full Version : Passing a URL works sometimes, but not often

06-06-2006, 07:09 PM
I have an interesting (horribly frustrating) problem here. My goal is to write a Euchre game in JavaScript. I am using a PHP script to update game information and retrieve the current game status. The following code is a snippet of JavaScript, where http is an XMLHttpRequest object.

http.open("GET", "euchre_play.php" + location.search + "&card=" + card, false);

The location.search property contains the string "?table=XX&player=XX". This is passed in to the JavaScript game client as the query portion of the url. By simply passing this string along to the PHP script, I avoid having to parse it in the JavaScript. I have another bit of code in my JavaScript which is nearly exactly the same... it just uses a different PHP script, and that part works fine.

The problem is, the above code does not always work. I have actually gotten it to work on occasion, exactly as written. I usually accomplish this by using a single string, fully formed URL. I can then strip off parts of that URL one by one and replace other parts with variables, such as 'location.search' and 'card'. However, what usually happens is that the first time I run the script as written above, it works! Subsequently, it fails to work every time!

06-06-2006, 07:26 PM
Also, I should mention that I have tried using an IFrame instead of an XMLHttpRequest object, with the exact same outcome... sometimes it works, but the vast majority of the time it does not.

I have also used an alert box to notify me of what my url string looks like, and it looks perfectly reasonable. For instance, something like "euchre_play.php?table=1&player=4&card=2"

06-06-2006, 08:48 PM
After looking at every bit of code for hours on end, I finally found an error in my php script. Thanks if you actually looked at this, but I hope you didn't waste your time.