jQuery Tokeninput添加(如果不存在) [英] jQuery Tokeninput add if not exists

查看:219
本文介绍了jQuery Tokeninput添加(如果不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写基于用户输入的脚本

I am in the process of writing a script that builds upon user input,

我有一些字段需要从数据库中查询其值,

I have some fields that its values need to be quired from the database,

如果没有找到条目,我想添加一个新值,以便下一个用户通过自动完成功能找到它.

and if no entry found I want to add a new value so the next user will find it through autocomplete.

我发现这件好看的&易于实现的名为TokenInput的jquery插件,但似乎没有

I found this great looking & easy to implement jquery plugin called TokenInput, but it doesn't seem to

接受我的数据库查询中不可用的条目.

accept entries that are not available in my database query.

以下是插件的链接: http://loopj.com/jquery-tokeninput/demo .html

是否有解决方法?还是建议另一个已经具有此功能的插件.

我有点担心这种网站的安全性,在进行这种实现时我需要注意一些特别的事情吗?

And I'm a little bit concerned about the security aspect of this sort of websites is there something special I need to take care of when doing this sort of implementation ?

推荐答案

在字段上启用tokenInput时,

When you enable tokenInput on a field,

$(selector).tokenInput(url, ...

该URL是tokenInput发送搜索查询的位置.它指向一个脚本,该脚本根据与搜索查询匹配的数据库条目返回建议.当数据库中没有与搜索查询匹配的情况时,您想要的是让该脚本向该列表添加另一个建议.如何执行此操作很大程度上取决于脚本.

that url is where tokenInput sends search queries. It points to a script which returns suggestions based on database entries matching the search query. What you want is to have that script add another suggestion to the list for that case when nothing in your database matches the search query. How to do this depends very much on the script.

因为您用php标记了问题,所以我猜测url指向一个php脚本,该脚本返回一个充满建议的JSON对象.在这种情况下,请修改php脚本,以便它向列表中添加一个 new 建议:

Because you tagged your question with php, I'm guessing the url points to a php script which returns a JSON object full of suggestions. In that case, modify the php script so that it adds a new suggestion to the list:

"{id: " . $idForThisNewSuggestion . ", name: \"" . $searchQueryString . " (new suggestion)\"}"

这篇关于jQuery Tokeninput添加(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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