繁体   English   中英

使用PHP脚本作为源的jQuery自动完成

[英]JQuery autocomplete using php script as source

我正在使用以下代码将源定义为php脚本:

$("#fav_rides_select").autocomplete({
            source: "http://localhost/coaster/CoasterInsider/index.php?page=getRideAndParksJson&type=rides&keyword=test",
            minLength: 1,
            delay: 1000,
            select: function( event, ui ) { 
                        //window.location.href = ui.item.valuea;
                        alert(ui.item.label);
            }
            }).data( "autocomplete" )._renderItem = function( ul, item ) {
                return $( "<li></li>" )
                    .data( "item.autocomplete", item )
                    .append( '<a><div class="autocompleteItemDiv"><div class="autocompleteImageDiv"><img src="' + item.image + '"></div><div class="autocompleteTextDiv">' + item.label + '<br/>' + item.description + '</div></div></a>' )
                    .appendTo( ul );
            };
    });

并没有显示任何结果,但是当我在浏览器中明确输入上述网址时,它会在浏览器中正确显示以下输出:

 [ {label:"Alton Towers" , valuea:"http://alto1.com" , description:"Alton tower parks" ,image:"images/altontowerslogothumb.png"}, {label:"Animal Kingdom" , valuea:"http://alto2.com" , description:"Animal Ride" ,image:"images/animalkingdomlogothumb.png"}, {label:"Busch Garden" , valuea:"http://alto3.com" , description:"Jeorge Bush" ,image:"images/buschgardenslogothumb.png"}, {label:"Chessingona" , valuea:"http://alto4.com" , description:"Play chessy" ,image:"images/chessingonlogothumb.png"}, {label:"Disneyland Paris" , valuea:"http://alto5.com" , description:"Visit parisano disney" ,image:"images/disneylandparislogothumb.png"}, {label:"Epcota" , valuea:"http://alto6.com" , description:"Epcot park" ,image:"images/epcotlogothumb.png"}, {label:"Fujia" , valuea:"http://alto7.com" , description:"Fujiyama" ,image:"images/fujilogothumb.png"}, {label:"Gardland" , valuea:"http://alto8.com" , description:"Gards here" ,image:"images/gardalandlogothumb.png"} ];

根据jQuery自动完成文档的source can be String, Array, Callback (javascript function)

可能您需要:

$("input").autocomplete({
  source: function(request, response) {
    $.ajax({
      url: "url",
      data: request,
      dataType: "json",
      method: "post",
      success: response
    }
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM