Jump to content

basic ajax-mysql sample works in IE but NOT in Firefox...


Recommended Posts

Hi, all:

I borrowed this small ajax sample from a site and it does work in IE but for some reason just doesnt work in Firefox.

Appreciate any help, feedback on this...

This is the code:

 

THIS IS FIRST FILE, CALL IT "index.php" that has ajax bit, and the form-submit:

 

<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onChange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html> 

 

THIS IS SECOND FILE, CALL IT "getuser.php", that gets called by the ajax from the index.php page:

 

<?php
$q=$_GET["q"];

$con = mysql_connect('host', 'user', 'password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);

$sql="SELECT * FROM items WHERE id = '".$q."'";
$result = mysql_query($sql);

echo "<table id='itemDisplay' border='0'>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><span style='font-family:times;font-size:18pt;color:993300'><strong>" . $row['id'] . " - " . $row['title'] . "</strong></span><br>" .$row['description'] . "<br><strong>Price: $" . $row['price'] ." / Shipping: $" . $row['shipping'] . "</strong></td>";
  echo "<td><img height='150' src='" . $row['imagesmall'] . "'/></td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?> 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.