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);
-
http.send(null);
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!