I created a form for searching through a parts library that I have stored in a MySQL database. I'm not new to web programming but this is my first time using PHP and Ajax. I have four listboxes that are chained together. In other words, if you click on the first one it filters out what's available in the next three. If you click on the 3rd one, it filters out the available options in the 4th one, etc. I do this by having php pages for each listbox and use ajax calls whenever the selected item changes in a listbox.
Everything was working beautifully and then I had somebody else try it (using the same version if Firefox) and they found that sometimes not all four listboxes load. If you keep hitting refresh you'll always get the first one, sometimes you'll get all four, and any one of the last three are hit and miss. I found out that if Firebug is running that the issue never happens but if you disable Firebug I can re-create the issue. This is with the initial loading of the page.
I have no idea how to debug this since it doesn't happen when Firebug is running. I use a different XMLHttpRequest for each call, so they shouldn't be conflicting with each other.
I'll include one example but the code for all the listboxes is the same.
javascript:
Expand|Select|Wrap|Line Numbers
- function setPartType(form)
- {
- var url="getPackage.php?";
- url = url+appendParmsToUrl(form);
- xmlhttpPartType=GetXmlHttpObject();
- if (xmlhttpPartType==null)
- {
- alert ("Browser does not support HTTP Request");
- return;
- }
- url=url+"sid="+Math.random()+"&";
- xmlhttpPartType.onreadystatechange=stateChangedPartType;
- xmlhttpPartType.open("GET",url,true);
- xmlhttpPartType.send(null);
- setPackage(form);
- }
- function stateChangedPartType()
- {
- if (xmlhttpPartType.readyState==4)
- {
- document.getElementById("packageSelect").innerHTML=xmlhttpPartType.responseText;
- }
- }
Expand|Select|Wrap|Line Numbers
- <?php require_once('../Connections/admin.php'); ?>
- <?php require_once('../Connections/phtdeelib.php'); ?>
- <?php require_once('functions.php'); ?>
- <?php
- mysql_select_db($database_phtdeelib, $phtdeelib);
- $query = "SELECT DISTINCT Package FROM components WHERE ";
- $query = $query . addToQuery($_SERVER['QUERY_STRING'], "partType", "PartType");
- $query = $query . "Package IS NOT NULL ORDER BY Package ASC;";
- $PartTypes = mysql_query($query, $phtdeelib) or die(mysql_error());
- $row_PartTypes = mysql_fetch_assoc($PartTypes);
- $totalRows_PartTypes = mysql_num_rows($PartTypes);
- ?>
- <select multiple size=5 name="Package" style="width: 15em;" onchange="setPackage(this.form);">
- <option value=""></option>
- <?php
- do {
- echo "<option value=\"" . $row_PartTypes['Package'] . "\"";
- if ($row_PartTypes['Package'] == $partType)
- echo " selected ";
- echo ">" . $row_PartTypes['Package'] . "</option>";
- } while ($row_PartTypes = mysql_fetch_assoc($PartTypes));
- ?>
- </select>
Anyone have any idea what could be going on? Any ideas on how to debug the problem would be appreciated as well.
Thanks guys!