jQuery的自动完成与PHP源代码 [英] Jquery autocomplete with php source

查看:102
本文介绍了jQuery的自动完成与PHP源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用jQuery的自动完成功能用PHP文件作为来源。我不明白为什么它不工作。如果我使用一个变量的一切输入的数据工作正常。希望有人能提供帮助。预先感谢您的答复。干杯。马克。

我的HTML:

 <输入ID =MOI类型=文本/>

我的JS:

  $(函数(){
        $(#moi).autocomplete({
            来源:PHP / search_loc.php
            的minLength:2
        });
    });

我的PHP:

 < PHP
标题(内容类型:text / html的;字符集= utf-8');
要求(../ INC / connect.inc.php);
mysql_set_charset('UTF8');$结果= mysql_query(SELECT * FROM search_loc);
$行= mysql_fetch_assoc($结果);而($行= mysql_fetch_assoc($结果)){
    回声$行['srl_loc']。'< BR>';}?>


解决方案

您的PHP脚本应该返回JSON数据,

在jQuery UI的自动完成文档

 数据源是一个服务器端脚本返回JSON数据,

I would like to use the jquery autocomplete "function" with a php file as the source. I don't get why it is not working. If I use data entered in a variable everything works fine. Hope someone can help. Thank you in advance for your replies. Cheers. Marc.

My HTML:

<input id="moi" type="text"/>

My JS :

$(function() {
        $( "#moi" ).autocomplete({
            source: "php/search_loc.php",
            minLength: 2
        });
    });

My PHP:

<?php
header('Content-Type: text/html; charset=utf-8');
require("../inc/connect.inc.php");
mysql_set_charset('utf8'); 

$result = mysql_query("SELECT * FROM search_loc");
$row=mysql_fetch_assoc($result);

while($row=mysql_fetch_assoc($result)){
    echo $row['srl_loc'].'<br>';}

?>

解决方案

Your PHP script should return JSON data,

In the Jquery UI autocomplete doc

The datasource is a server-side script which returns JSON data,

这篇关于jQuery的自动完成与PHP源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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