首页 > 解决方案 > 来自 PostgreSQL 的 Ajax 自动完成文本框未获取数据

问题描述

我正在尝试让我们 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({
            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);
                    }
                });
            }
        }); 

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

标签: phpajaxpostgresqlautocomplete

解决方案


推荐阅读