weixin_33698043 2010-12-08 12:30 采纳率: 0%
浏览 50

使用AJAX的jQuery自动完成

I'm trying to write a JQuery autocomplete script which will call a url via AJAX and update autocomplete results as user enters data into the form.

I have my AJAX setup and currently returning JSON. But I don't know how to go about getting the autocomplete function to call it and use the response. I have managed to get the following working, but this is static data, so no good for my task:

$("input#name").autocomplete({
        source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
});

Cheers.

  • 写回答

1条回答 默认 最新

  • 关注

    http://jqueryui.com/demos/autocomplete/#remote

        $( "#birds" ).autocomplete({
            source: "search.php",
            minLength: 2,
            select: function( event, ui ) {
                log( ui.item ?
                    "Selected: " + ui.item.value + " aka " + ui.item.id :
                    "Nothing selected, input was " + this.value );
            }
        });
    

    The php needs to return values in Json format like this http://jqueryui.com/resources/demos/autocomplete/search.php?term=ai

    Json instructions http://us2.php.net/json

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型