mac007 Posted December 11, 2010 Share Posted December 11, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/221280-basic-ajax-mysql-sample-works-in-ie-but-not-in-firefox/ Share on other sites More sharing options...
Adam Posted December 13, 2010 Share Posted December 13, 2010 Do you get an error in the error console? Quote Link to comment https://forums.phpfreaks.com/topic/221280-basic-ajax-mysql-sample-works-in-ie-but-not-in-firefox/#findComment-1146707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.