所以,我在我的网站上开发了一个实时搜索功能,但毫不奇怪,它似乎在 Internet Explorer 中不起作用。我已经测试过,它在 IE9 和 IE8 中不起作用,我知道它在 Chrome 和 Fire Fox 中可以正常工作。我使用的 Ajax 来自 W3Schools 网站,它似乎在那里工作。它甚至可能是我使用的 PHP,但我不确定问题是什么。我只是猜测它是 Ajax 还是 PHP。有谁知道怎么了?如果有帮助,它位于 -RETRACTED URL-。谢谢!
我的 HTML 文档中的 Ajax:
<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:
<?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
}
?>