php - 来自 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 请求中的问题。
我很感激任何帮助。
解决方案
推荐阅读
- javascript - 我该怎么做才能避免放“”?
- excel - 如何修复 Excel 中的 VBA 代码,以根据其值删除某些图表图例条目?
- json - How to decode an array of JSON inside another array
- python - 将元素附加到列表时python程序冻结
- angular - 如何在导出函数和命名空间类型的角度应用程序中导入“npm”模块?
- c# - 将 HTML 标题附加到 Spire PDF
- python - 在 Python 中返回嵌套 JSON 对象中的值
- java - 使用 Poiji 从 excel 获取对象列表到 Dataprovider
- spring - 在 SpringBoot 2.1 中确定传入 RequestEntity 的 HTTP 版本
- python - 只有在至少具有特定长度的情况下,有没有办法用逗号分割字符串?