drtzb06222 2016-11-11 22:58
浏览 49
已采纳

使用DB2从autocomplete jquery UI返回的未定义值

I have the following code that works like a charm with mysql but when implemented using DB2, it returns value "undefined" where should be the actual value.

consult.php

require_once("connect_db.php");

$action = (isset($_GET['action'])) ? $_GET['action'] : '';
$param = (isset($_GET['parameter'])) ? $_GET['parameter'] : '';

if($action == 'autocomplete'):
    $where = (!empty($parameter)) ? "WHERE name LIKE '%{$parameter}%'" : "";
    $sql = "SELECT LOWER(name) FROM categories " . $where;

    $stmt = db2_prepare($connection, $sql);

        db2_execute($stmt);
        $data = db2_fetch_object($stmt);

    $json = json_encode($data);
    echo $json;
endif;

categories.js

$(function() {

$( "#category" ).autocomplete({
        minLength: 1,
        source: function( request, response ) {
            $.ajax({
                url: "consult.php",
                dataType: "json",
                data: {
                        action: 'autocomplete',
                    parameter: $('#category').val()
                },
                success: function(data) {
                   response(data);
                }

            });
        },

})
.autocomplete( "instance" )._renderItem = function( p, item ) {
  return $( "<p>" )
    .append( "<a><b>" + item.name + "</b></a>" )
    .appendTo( p );
};

});
  • 写回答

1条回答 默认 最新

      报告相同问题?

      悬赏问题

      • ¥15 echarts地图添加点击事件
      • ¥15 不知道带什么标题好随便搞一个吧
      • ¥15 ffmpeg 图片合成视频
      • ¥15 软科大学爬取获取所有数据
      • ¥15 如何修改损失函数以及代码讲解
      • ¥15 有偿咨询!!程序的小数点怎么取到后四位啊!
      • ¥15 IRS智能反射面相关文章代码
      • ¥15 landsat5的两幅影像镶嵌前波段是123457,为什么镶嵌后波段变成了123456?
      • ¥15 关于#matlab#中fmincon函数如何处理约束问题?
      • ¥60 Java程序,控制台输出