jQuery UI autocomplete: how to send post data?

后端 未结 5 1868
伪装坚强ぢ
伪装坚强ぢ 2021-02-20 17:25

From jQuery UI site (veiw source):

$( \"#birds\" ).autocomplete({
    source: \"search.php\",
    minLength: 2,
    select: function( event, ui ) {
        log(          


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 18:03

    I had this same need and no single example from stackoverflow was working properly.

    By testing diffrent authors contributions and tweaking here and there the below example is most likely what anyone would be looking for in an autocomplete that

    1. Send out POST request.

    2. Does not require tweaking the main autocomplete UI.

    3. Sends out multiple parameters for evaluation.

    4. Retrieves data from a database PHP file.

    All credit is to the many persons whom i used their sample answers to make this working sample.

            $( "#employee_name" ).autocomplete({
            source: function (request, response) {
            $.ajax({
            type: "POST",
            url:"employees.php",
            data: {term:request.term,my_variable2:"variable2_data"},
            success: response,
            dataType: 'json',
            minLength: 2,
            delay: 100
                });
            }});
    

提交回复
热议问题