【发布时间】:2016-11-20 14:29:34
【问题描述】:
我已阅读有关我的问题的所有主题,但无法解决我的问题。我想使用 jQuery AJAX 获取 php 函数结果。
function fetch_select(){
val_name = $('#name').val();
$.ajax({
type: 'POST',
url: 'include/get_db.inc.php',
data: {
name: val_name,
},
success: function (response) {
document.getElementById('higtchart_medie_gen').innerHTML=response;
columnChart( JSON.parse(response));
}
});
}
function columnChart(data_v){
if(data_v.length >0){
$(function () {
$('#higtchart_medie_gen').highcharts({
chart: {
type: 'column'
},
......
#name 是选择标签的 ID。
我的 get_db.inc.php 代码是:
<?php
function test_name () {
$ret = [];
if(isset($_POST['name'])){
$name = $_POST['name'];
$sql = "SELECT
......
WHERE ID = $name ";
$result = $conn->query($sql);
if($result->num_rows > 0){
while($row = $result->fetch_assoc()) {
$ret [] = [$row['NAME'] . ' ' . $row['LASTN'], floatval($row['AVGG'])];
}
}
}
if(count($ret) >1) echo json_encode($ret);
else echo 'Not working';
}
?>
如何从 Ajax 代码调用 test_name 函数? 非常感谢!
【问题讨论】:
-
我看到了那个帖子和许多其他帖子。我在圈子里跑了 4 天试图解决这个问题,但我没有成功。
标签: javascript php jquery ajax