mysql php js实时搜索 [英] mysql php js live search

查看:94
本文介绍了mysql php js实时搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在基于Jquery/ajax/php进行实时搜索,但是似乎很有效. 你们能在我的代码中发现问题吗? :)

I'm currently doing a live search form based on Jquery/ajax/php, but it dosent seems to work. Can you guys se a problem in my code? :)

function getStates(value) {
  $.post("search.php",{ partialState: value }, function(data) { 
    $("#results").html(data);
  });
}

<input type="text" onkeyup="getStates(this.value)" />
<div id="results"></div>

Search.php:

Search.php:

$partialStates = $_POST['partialState'];
$states = mysql_query("SELECT institution_name FROM sb_institutions WHERE institution_name LIKE '%$partialStates%'");

while($stateArray = mysql_fetch_array($states)) {
    echo "<div>" . $state['institution_name'] . "</div>";
}

谢谢! :)

推荐答案

您的代码看起来还可以.

Your Code looks ok.

对ajax进行故障排除的最佳方法是使用具有Firebug扩展功能的Firefox.

The best way to troubleshoot ajax is to use Firefox with Firebug extension.

这样,您可以看到:

  1. 该功能是否被触发
  2. 如果$ _POST值合适,则为url +参数
  3. 服务器作为响应发送的内容
  4. 如果您的js错误

  1. if the function is being fired
  2. if the $_POST values are good : url + parameters
  3. what the server sends as a response
  4. if you have errors in your js

所有这些都将在firebug的控制台选项卡中. 安装Firebug后,右键单击该页面,然后选择使用Firebug调试".

All this will be in the console tab of firebug. after installing firebug right click on the page and choose debug with firebug.

这篇关于mysql php js实时搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆