【问题标题】:php mysql wordpress autocomplete not workingphp mysql wordpress自动完成不起作用
【发布时间】:2013-03-25 19:00:38
【问题描述】:

我已链接到用于自动完成和 jquery 的适当 ajax 库。这是脚本

 jQuery(document).ready(function($) {
 $("#tag").autocomplete("data.php", {
  selectFirst: true
   });
  });

还有我的 data.php 文件

    $q = $_GET["q"];
   $my_data=mysql_real_escape_string($q);
  $sql="SELECT comname FROM wp_birds WHERE comname LIKE '%$my_data%' ORDER BY comname";
  $result = mysql_query($sql) or die(mysql_error());
  if($result)
  {
   while($row=mysql_fetch_array($result))
    {
   echo $row['comname']."\n";
   }
 }

还有我的表格

<label>Tag:</label>
<input name="tag" type="text" id="tag" size="20"/>

data.php 文件成功加载了逗号数组,但是当我输入时我什么也没有得到...

【问题讨论】:

    标签: php wordpress autocomplete


    【解决方案1】:

    jquery 无冲突包装器

    jQuery(document).ready(function($) {
        $("#tag").autocomplete("data.php", {
          selectFirst: true
        });
    });
    

    参考:http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers

    更新:

    您还需要使用 ajax 检索您的源代码

    http://jqueryui.com/autocomplete/#remote

    【讨论】:

    【解决方案2】:

    wordPress 中包含的 jquery 库以“无冲突”模式加载。这样做是为了防止与其他 javascript 库的兼容性问题。在“无冲突”模式下,$ 快捷方式不可用,使用较长的 jquery,示例:

    jQuery(document).ready(function ($) {

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      相关资源
      最近更新 更多