从 AutoSuggest jQuery 代码中拆分 jQuery CSV 中的值
我目前正在使用 - http://code.drewwilson.com/entry/autosuggest-jquery-我网站上的自动建议插件。我将选项数量限制为 3 个。
这是自动建议代码:
<script type="text/javascript">
$(document).ready(function() {
$("input[id=category]").autoSuggest("http://localhost:8888/bl/pages_mx/category_1.php",
{selectedItemProp: "name", selectedValuesProp: "value", searchObjProps: "name",
minChars: 1, matchCase: false, selectionLimit: 3});
});
</script>
访问者可以选择的类别取自 MYSQL 数据库内的表。现在,当我开始输入潜在类别时,我可以成功看到建议!
从“category”表中查询的 2 个值是:category_ID 和 name。
我的问题是,一旦用户选择了 1,2 或 3 个选项,我如何在 php 中的 3 个不同变量或数组中获取类别 ID?
我在他们的讨论论坛上最接近的帮助是使用这段代码:
var arr = $(".as-values").val().split(",");
但是从那里,我不知道如何实现这个?
我尝试使用爆炸功能来分割 CSV:
<?php if($_POST['category_submit']){ ?>
<script type="text/javascript">
var arr = $(".as-values").val().split(",");
var exploded = arr.split(',');
var category_1=exploded[0];
var category_2=exploded[1];
var category_3=exploded[2];
print (category_1);
</script>
<?php } ?>
但是当我按提交时似乎没有打印任何内容?
任何帮助将不胜感激。
非常感谢!
但似乎什么也没有
I am currently using - http://code.drewwilson.com/entry/autosuggest-jquery-plugin for an autosuggest on my site. I have limited the number of choices to 3.
This is the autosuggest code:
<script type="text/javascript">
$(document).ready(function() {
$("input[id=category]").autoSuggest("http://localhost:8888/bl/pages_mx/category_1.php",
{selectedItemProp: "name", selectedValuesProp: "value", searchObjProps: "name",
minChars: 1, matchCase: false, selectionLimit: 3});
});
</script>
The categories the visitor can choose is taken from a table within the MYSQL database. I can now successfully see the suggestions when I begin to type in potential categories!
The 2 values that are queried from the 'category' table are - category_ID and name.
My question is, once the user has chosen their 1,2 or 3 choices, how can I get the category_ID in 3 different variables in php, or in an array?
The closest I have got to help on their discussion forum is by using this code:
var arr = $(".as-values").val().split(",");
But from there, I have no idea how to implement this?
I have tried using an explode function to split the CSV using this:
<?php if($_POST['category_submit']){ ?>
<script type="text/javascript">
var arr = $(".as-values").val().split(",");
var exploded = arr.split(',');
var category_1=exploded[0];
var category_2=exploded[1];
var category_3=exploded[2];
print (category_1);
</script>
<?php } ?>
But nothing seems to print when I press submit?
Any help would be hugely appreciated.
Many thanks!
But nothing seems
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,写JavaScript的时候,写JavaScript很重要。 “Print”不是有效的 JavaScript 行。
其次,当您调用
.split()
时,您得到的是一个可立即索引的数组。First, it's important to write JavaScript when writing JavaScript. "Print" is not a valid line of JavaScript.
Second, when you call
.split()
, what you get is an array that's immediately indexable.