dream2891 2016-11-14 20:41
浏览 23

使用jQuery自动完成字段

I am trying to populate multiple fields with jQuery from user input in one form but I'm not getting any result in JSON. Can anyone spot what the problem is?

$('#countryname_1').autocomplete({
    source: function( request, response ) {
    $.ajax({
        url : 'search.php',
        dataType: "json",
        data: {
           name_startsWith: request.term,
           type: 'country_table',
           row_num : 1
        },
         success: function( data ) {
             response( $.map( data, function( item ) {
                var code = item.split("|");
                return {
                    label: code[0],
                    value: code[0],
                    data : item
                }
            }));
        }
    });
},
autoFocus: true,
minLength: 0,
select: function( event, ui ) {
    var names = ui.item.data.split("|");
    $('#country_no_1').val(names[1]);
    $('#phone_code_1').val(names[2]);
    $('#country_code_1').val(names[3]);
}
});

The PHP I'm using to query the database

require ($_SERVER['DOCUMENT_ROOT'].'/config/dbconnect.php');

if(isset($_POST['type']) == 'country_table'){
$result = $db->prepare("SELECT firstname, department FROM users where      firstname LIKE '".strtoupper($_POST['name_startsWith'])."%'");
$data = array();
while ($row->fetch(PDO::FETCH_ASSOC)){{
    $name = $row['firstname'].'|'.$row['department'].'|'.$row_num;
    array_push($data, $name);
}
echo json_encode($data);
}
}

Nothing appears in the form and Chrome shows that no data is being passed back

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图