Jquery + PHP:从第三方 PHP 脚本获取自动完成字符串
Jquery 搜索示例:
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$("#tags").autocomplete({
source: availableTags
});
});
</script>
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
</div>
<!-- End demo -->
<div class="demo-description">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source- option.</p>
</div>
<!-- End demo-description -->
基本上有一个带有自动完成内容的变量,这很好,除了我需要一些可能更复杂的东西。我不需要从 var/xml/sql 提供列表,而是需要从第三方 php 脚本发出的 echo 中获取。
该 php 脚本将根据查询回显相应的信息。即:用户搜索 customsearch.php?q=Lemons 它将回显“Pineapples”。
有人可以帮助我吗?
Jquery search by example:
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$("#tags").autocomplete({
source: availableTags
});
});
</script>
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
</div>
<!-- End demo -->
<div class="demo-description">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source- option.</p>
</div>
<!-- End demo-description -->
There's basically a variable with the autocomplete content, and that's great and all, except I need something perhaps a little more complex. Instead of providing a list from a var/xml/sql I need to grab from an echo issued by a third party php script.
That php script will echo out the appropriate information depending on the query. i.e.: the user searches for customsearch.php?q=Lemons it will echo "Pineapples".
Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的其他问题,我假设您'正在进行 AJAX 调用来获取搜索结果。将它们加载到数组中并在示例中替换它:
理想情况下,您不会将 async 设置为 false,但如果您不熟悉回调,我会尽量不让您的大脑爆炸。
Based on your other question, I'd assume you're making an AJAX call to get the search results. Load them into an array and replace it in your example:
Ideally you wouldn't set async to false, but I'm trying not to make your brain explode if you aren't familiar with callbacks.