来自PostgreSQL的Ajax自动完成TextBox没有获取数据

时间:2018-05-25 04:00:16

标签: php ajax postgresql autocomplete

我正在尝试向我们Ajax调用一个php脚本,它从我的PostgreSQL中获取数据在php中,我的代码是:

    <?php


# Includes
require("database.inc.php");
require("json.inc.php");

# Retrive URL arguments
$table = $_REQUEST['table'];
$fields = isset($_REQUEST['fields']) ? $_REQUEST['fields'] : '*';
$parameters = isset($_REQUEST['parameters']) ? " where " . $_REQUEST['parameters'] : '';
$order = isset($_REQUEST['order']) ? " order by " . $_REQUEST['order'] : '';
$limit = isset($_REQUEST['limit']) ? " limit " . $_REQUEST['limit'] : '';

# Perform the query
$sql = "select " . $fields . " from " . $table . $parameters . $order . $limit;
$db = pgConnection();
$statement=$db->prepare( $sql );
$statement->execute();

# send JSON or JSONP results
sendJSON($statement);

?>

这是我的Ajax:

            $.ajax({
            url: "ws_geo_attributequery.php",
            //table:'address',
            //fields:'file_as_na',
            type:'GET',
            dataType: "jsonp",
            data: {
                'table:':'address',
                'fields':'file_as_na',
                id: 1

                },


            success: function(response){
                var data = $(response).map(function(){
                    return {value: this.file_as_na, id: this.id};
                }).get();

                $('#name').autocomplete({
                    source: data,
                    minLength: 0,
                    select: function(event,ui){
                        $('input#id').val(ui.item.id);
                    }
                });
            }
        }); 

我的Db没有得到任何结果。我确定我的ajax请求中的问题 我很感激任何帮助。

0 个答案:

没有答案