我如何使用PHP数据提供给jQuery的自动完成? [英] How do I use php to feed data to jQuery autocomplete?

查看:133
本文介绍了我如何使用PHP数据提供给jQuery的自动完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个形式,其中某些文本字段和文本区域具有自动完成。

I'm trying to build a form where certain text fields and text areas have autocomplete.

我用强大的插件字preSS打造自己的状态。我使用的是 jQuery的自动完成插件为自动完成的部分。

I've used the formidable plugin for wordpress to build my form. I'm using the jQuery autocomplete plugin for the autocomplete part.

在code是这样的:

<script>

            $(document).ready(function(){
                var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" ");
            $("#example").autocomplete(data);
  });
  </script>

所以基本上我需要使用PHP来从MySQL数据库中提取数据,并将其输送到数据变种。我是一个PHP新手,所以我不知道如何做到这一点。一个codeR谁在强大的插件工作提出以下code为VAR数据部分:

So basically I need to use php to pull data from the mysql database and feed it to that data var. I'm a php newbie, so I'm not sure how to do this. A coder who works on the formidable plugin suggested the following code for the var data part:

 <?php
global $frm_entry_meta;
$entries = $frm_entry_meta->get_entry_metas_for_field($field_id, $order='');
?> //db_frm_entry_metas is the name of the mysql db that stores the values for every field from the form. I suspect get_entry_metas_for_field is a function added by the formidable plugin. $field_id is the id for a given field on the form. 
var data = new Array();
<?php foreach($entries as $value){ ?>
data[] = <?php echo $value ?>;

<?php } ?>

我试图与在$ FIELD_ID的地方一个ID号运行此code,但没有奏效。我在这里卡住了。

I tried to run this code with an id number in the place of $field_id, but it didn't work. I'm stuck here.

我能理解大部分的code,除了这一部分:

I can understand most of the code, except for this part:

var data = new Array();
<?php foreach($entries as $value){ ?>
data[] = <?php echo $value ?>

我不明白是什么[]是做有数据......应该在PHP是数据反馈到VAR数据=行?

I don't get what the data[] is doing there... should the php be feeding the data to the var data= line?

我有大约15形式的文本/文本区域字段,其中每一个需要拉与其给定FIELD_ID相关联的数据。除非有一个更简单的方式来做到这一点,这意味着我得写15脚本,每一个特定的$ FIELD_ID和jQuery对象与现场的CSS选择器。

I have around 15 form text/textarea fields, each of which needs to pull data associated with its given field_id. Unless there's an easier way to do this, this means I'll have to write 15 scripts, each with a particular $field_id and jQuery object with field's css selector.

任何得到这个工作帮助将非常AP preciated!

Any help getting this to work would be much appreciated!

推荐答案

在codeR是错误的,这样的:

The coder is wrong, this:

data[] = something;

将导致JS语法错误,这是一个PHP的速记推动成员数组和JS不起作用。

will cause a syntax-error in JS, it's a PHP-shorthand for pushing members to an array and doesn't work in JS.

试试这个:

data.push(unescape('<?php echo rawurlencode($value); ?>');

这篇关于我如何使用PHP数据提供给jQuery的自动完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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