So, I have developed a live search function on my site but, no big surprise, it doesn’t seem to work in Internet Explorer. I have tested and it won’t work in IE9 and IE8 and I know it works as I want in Chrome and Fire Fox. The Ajax I used I took from the W3Schools website and it seems to be working there. It might even be the PHP I used, but I’m not really sure what the problem is. I’m just guessing that it’s either the Ajax or PHP. Anyone know what’s wrong? It is located at -RETRACTED URL- if it helps. Thanks!
Ajax in my HTML document:
<script type="text/javascript">
var keyword = ''; // add this!
var city = ''; // add this!
var state = ''; // add this!
var country = ''; // add this!
function showHint(keyword, city, state, country) {
var xmlhttp;
if(keyword.length == 0 && city.length == 0 && state.length == 0) {
document.getElementById("txtHint").innerHTML = "";
}
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", "gethint.php?keyword=" + keyword + "&city=" + city + "&state=" + state + "&country=" + country, true);
xmlhttp.send();
}
</script>
PHP for the live search:
<?php
//get the parameters from URL
$keyword = $_GET['keyword'];
$city = $_GET['city'];
$state = $_GET['state'];
$country = $_GET['country'];
$query = mysql_query("SELECT * FROM users WHERE ClinicName LIKE '%$keyword%' AND LocationCity LIKE '%$city%' AND LocationRegion LIKE '%$state%' AND LocationCountry LIKE '%$country%' ORDER BY ClinicName ASC") or die(mysql_error());
if($query){//If query successfull
if(mysql_affected_rows()!=0){//and if atleast one record is found
echo '
<tr>
<th>Clinic Name</th>
<th>Phone Number</th>
<th>Location</th>
</tr>';
while($rows = mysql_fetch_array($query)){ //Display the record
$replace = str_replace(" ", "-", $rows['ClinicName']);
echo '
<tr>
<td><a href="clinic.php?userid='.$rows['UserID'] .'">'.$rows['ClinicName'].'</a></td>
<td>'.$rows['Phone1'].'-'.$rows['Phone2'].'-'.$rows['Phone3'].'</td>
<td>'.$rows['LocationCity'].', '.$rows['LocationRegion'].' '.$rows['LocationZip'].', '.$rows['LocationCountry'].'</td>
</tr>';
}
}
else {
echo 'No Results for:<br />Clinic Name: '.$keyword.'<br />City: '.$city.'<br />State: '.$state.'<br />Country: '.$country.'';//No Match found in the Database
}
}
else {
echo 'Parameter Missing in the URL';//If URL is invalid
}
?>
IE won’t let you innerHTML a table. You can find this information here: Microsoft