Getting jQuery autocomplete to work with PHP source

你说的曾经没有我的故事 提交于 2019-11-29 15:47:22
$.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

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!