Bootstrap typeahead不显示AJAX结果(Bootstrap typeahead is not displaying AJAX results)

编程入门 行业动态 更新时间:2024-10-24 10:22:13
Bootstrap typeahead不显示AJAX结果(Bootstrap typeahead is not displaying AJAX results)

在询问之前我想说这不是一个重复的话题。 我已经尝试过了:

Pwarelis的叉子 Tcrosen的一个 Gudbergur的代码

......还有很多其他人,我也阅读了很多问答 ,但这些都不是我想要的。 我尝试的所有内容都与预定义的字符串源一起使用,但是当我执行下一步:AJAX远程源时,它只是在下拉列表中显示没有结果。

更新 - 我的代码 (不明白为什么负面投票。写得好,结构良好;))

html文件

<html> <head> <link href="./bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" /> </head> <body> <input id="myElement" class="typeahead" type="text"> <script src="./js/jquery.js"></script> <script src="./bootstrap/js/bootstrap-typeahead.js"></script> <script language="javascript"> $('#myElement').typeahead({ ajax: '/php/ajax.php' }); </script> [...]

ajax.php文件:

<?php echo "[{ id: 1, name: 'Terry'}, { id: 2, name: 'Mark'}, { id: 3, name: 'Jack'}]"; ?>

这不是AJAX问题,因为它在其他情况下在同一台机器上工作。 我可以尝试修理它吗?几天后我真的崩溃了。 谢谢阅读。

Before asking I want to say that this is not a duplicated topic. I've already tried with:

Pwarelis' fork Tcrosen's one Gudbergur's code

...and many others, and I also read lots of Q&A, but none of them is what I am looking for. All what I tried works with predefinite string sources, but when I do the next step: AJAX remote source, it is just showing no results on the dropdown list.

UPDATE - My code (don't understand why negative votes. Well written, well strucuted ;))

The html file

<html> <head> <link href="./bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" /> </head> <body> <input id="myElement" class="typeahead" type="text"> <script src="./js/jquery.js"></script> <script src="./bootstrap/js/bootstrap-typeahead.js"></script> <script language="javascript"> $('#myElement').typeahead({ ajax: '/php/ajax.php' }); </script> [...]

The ajax.php file:

<?php echo "[{ id: 1, name: 'Terry'}, { id: 2, name: 'Mark'}, { id: 3, name: 'Jack'}]"; ?>

It's not an AJAX issue, because it is working in other cases at the same machine. What may I try to fix it?, I am really crashing up my head since a few days. Thanks for reading.

最满意答案

不知道正确答案的情况下投票否定的人应该在采取行动之前先思考一下。 如果有人需要一个真正的漂亮/工作/魔术自动完成脚本,那么我们去:

真正好的自动完成脚本

说明 :这会向文本字段添加建议值的下拉菜单。 用户可以直接单击建议将其输入到字段中,也可以使用向上和向下箭头键导航列表,使用回车键选择值。 建议列表的值将以XML或JSON (通过PHP脚本或类似方式)提供

谢谢那些消极点消失的人;)

People who vote negative without even knowing the right answer should think a bit before acting. If someone needs a real nice/working/magic autocomplete script, here wo go:

Real good Autocomplete Script

Description: This adds a pulldown menu of suggested values to a text field. The user can either click directly on a suggestion to enter it into the field, or navigate the list using the up and down arrow keys, selecting a value using the enter key. The values for the suggestion list are to provided as XML, or as JSON (by a PHP script, or similar).

Thanks those who made negative points disappear ;)

更多推荐

本文发布于:2023-08-01 12:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1358078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:typeahead   Bootstrap   AJAX   results   displaying

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!