weixin_33693070 2012-02-19 17:02 采纳率: 0%
浏览 36

冷融中的自动完成8

I need to add the autocomplete widget to search for a word from the database,even if the characters are in the middle of the word This My CFM page :

      <script src="jquery-1.4.2.min.js"></script>
      <script src="jquery-ui-1.8.custom.min.js"></script>
      <link rel="stylesheet" href="jquery-ui-1.8.custom.css" type="text/css" />

      <script type="text/javascript">
        $(document).ready(function(){ 
        $('#Names').autocomplete( 
                   {source: function(request, response) { 
                     $.ajax({ 
                     url: "cfc/getValues.cfc?method=getNames>&returnformat=json", 
                     dataType: "json", 
                     data: { 
                     search: request.term, 
                     maxRows: 10 
                     }, 
                  success: function(data) { 
                  response(data); 
                    }                    
                  }) 
              }, 
            parse: function(data){ 
                  return $.map(data, function(item) { 
                  return { data: item, value: item, result: item }; 
                }); 
               } 
             }); 
           }); 
      </script>

     category: <input id="Names" />

and this the CFC page:

    //cfc file getValues.cfc

   <cffunction name="getNames" access="remote" returntype="String" > 
     <cfargument name="search" type="any" required="false" default="">   
      <cfset var data=""> 
        <cfset var result=ArrayNew(1)> 
           <cfquery name="data" datasource="dbNAme"> 
            SELECT  NAME 
            FROM myTable 
            WHERE NAME LIKE '%#trim(ARGUMENTS.search)#%' 
            ORDER BY NAME 
           </cfquery> 
        <cfloop query="data"> 
        <cfset returnStruct = StructNew() /> 
        <cfset returnStruct["label"] = NAME />  
        <cfset ArrayAppend(result,returnStruct) /> 
        </cfloop>
       <cfreturn serializeJSON(result) /> 
       </cffunction>

No javascript error but i can't get it to work at all.when i write in the textbox nothing happens is there something wrong in my code?

  • 写回答

2条回答 默认 最新

  • weixin_33739541 2012-02-19 17:18
    关注

    Your search term is

    WHERE NAME LIKE '%#trim(ARGUMENTS.search)#%' 
    

    If I understand your question correctly for whole words it shoud be

    WHERE NAME LIKE '#trim(ARGUMENTS.search)#' 
    

    Notice have removed the % wildcard

    However you might also be asking the question "my autocomplete does not work at all" In this case I would download and install fiddler as this is a great debug tool and works brilliantly for debugging through AJAX calls.

    评论

报告相同问题?

悬赏问题

  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)