我有一个实时搜索的代码,可以在localhost上正常工作,但它不能在线工作。
这是代码:
的index.php:
<div id="explainMessage" class="explainMessage">Type your model inside the box above.</div>
</div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(function(){
$("#searchid").keyup(function()
{
var searchid = $(this).val();
var dataString = 'search='+ searchid;
if(searchid!='')
{
$.ajax({
type: "POST",
url: "search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#result").html(html).show();
}
});
}return false;
});
jQuery("#result").live("click",function(e){
var $clicked = $(e.target);
var $name = $clicked.find('.name').html();
var decoded = $("<div/>").html($name).text();
$('#searchid').val(decoded);
});
jQuery(document).live("click", function(e) {
var $clicked = $(e.target);
if (! $clicked.hasClass("search")){
jQuery("#result").fadeOut();
}
});
$('#searchid').click(function(){
jQuery("#result").fadeIn();
});
});
</script>
</body>
</html>
的search.php:
<?php
$db = new mysqli('host', 'user', 'psw', 'db');
if ($db->connect_errno > 0) {
die('Unable to connect to database [' . $db->connect_error . ']');
}
if ($_POST) {
$q = $_POST['search'];
$sql_res = "select one, two, three, four, from table where one like '%$q%' or two like '%$q%' order by field (three ,1,0)";
$result = mysqli_query($db, $sql_res);
if (mysqli_num_rows($result) == 0) {
$display = '<div id="explainMessage" class="explainMessage">Sorry, is not listed</div>';
echo $display;
} else {
while ($row = $result->fetch_assoc()) {
$one = $row['one'];
$two = $row['brand'];
$compatibility = $row['two'];
$three = $row['three'];
$four = $row['four'];
$b_one = '<strong>' . $q . '</strong>';
$b_two = '<strong>' . $q . '</strong>';
$final_one = str_ireplace($q, $b_one, $one);
$final_two = str_ireplace($q, $b_two, $two);
$display = '<div class="results" id="dbResults">ok</div>';
echo $display;
}
?>
<?php
}
}
?>
为什么它不能在线工作的任何想法?
感谢。
ps:如果我检查chrome控制台,则完全没有错误。
修改
解决了,这是用户权限的错误。 无论如何,谢谢大家。