Getting jQuery autocomplete to work with PHP source

前端 未结 2 932
慢半拍i
慢半拍i 2020-12-21 11:00

I have a jQuery autocomplete field with this code:

 var tags = [\"a\", \"ab\", \"abc\", \"abcd\", \"adbce\", \"abcdef\", \"abcdefg\", \"abcdefgh\", \"abcdefg         


        
相关标签:
2条回答
  • 2020-12-21 11:23

    I wrote this custom script to get drop downs working in our code when we didnt have json_encode available, hopefully it helps you to work something out.

    The 'get_xref_values()' function just builds an array from the parameters provided, and the GET - 'term' - is the text within your autocomplete text box, it gets added automatically by the control.

    The 'click' code just makes the autocomplete drop-down automatically when a user clicks it, as well as when they type.

    Here is the jquery:

    $("#libraryEventAspectRatio" ).autocomplete({
        source: "/dropDowns/autoXref.php?category=" + "aspectratio",
        matchContains: true,
        minLength: 0
    }).click(function(){
        $("#libraryEventAspectRatio" ).autocomplete('search', $(this).val());
    });
    

    and here is the php:

    //this page creates simple data for a drop down box to use (jquery's UI autocomplete)
    
    $category       = get_input_get("category");
    $description    = get_input_get("term");
    $select_field   = get_input_get("selectField");
    $select_value   = get_input_get("selectValue");
    
    $order_by       = "description";
    
    $xref_data      = get_xref_values($category, $order_by, $description, $select_field, $select_value);
    
    $str = "[";
    
    foreach ($xref_data as $row):
        $str .= '"' . $row['description'] . '",';
    endforeach;
    
    //chop off the last comma
    if (count($xref_data)) {
        $str = substr($str,0,-1);
    }
    
    $str .= "]";
    
    echo $str;
    
    0 讨论(0)
  • 2020-12-21 11:29
    $.ajax({
         url:"http://absolutepathtofile/autosuggest.php",
         type:"post",
         success:function(html){
             $("#user_phone").autocomplete(
                {position: {offset: "0 -10px"},
                source: html
             });
         }   
    });
    
    • work greate for me and tested
    0 讨论(0)
提交回复
热议问题