我用PHP和Highmaps(来自Highcharts库)构建了一个映射,它从SQL Server数据库加载数据。到目前为止一切都很好!但现在我想使用Ajax将映射中的值发送到另一个PHP页面,因为我想发送用户单击的点的名称。
series: {
cursor: 'pointer',
point: {
events:{
click:function(){
var myVariable = this.name;
$.get('my_page.php',{"brazil_state":myVariable});
}
}
}
}
在同一页面上完成此操作后:
<?php
$brazil_state = $_GET['brazil_state'];
$stmt = "select * from [DATABASE].[dbo].[MY_TABLE] where state = '{$brazil_state}'";
$stmt_exec = sqlsrv_query($conn, $stmt);
while($rows = sqlsrv_fetch_array($stmt_exec)){
print_r($rows);
}
?>
这会给我带来满足查询条件的所有结果,但参数并没有从JQueryAjax解析到PHP$_GET。
我已经找到了答案,但还没有找到。
提前感谢!!!
在第二个代码片段中,您引用了变量$_GET['myVariable'],但在ajax请求中使用的变量的名称:
$.get('my_page.php',{"brazil_state":myVariable});
是"brazil_state"
我找到了一种解决问题的方法:
series: {
cursor: 'pointer',
point: {
events:{
click:function(){
//open div with JQuery UI fold function
$( "#folder" ).show( "fold", 1000 );
//sends the request to details.php and brings the result into the div id='folder' on the current page
$.ajax({
url: 'details.php?state=' + this.name,
success: function(data) {
$('#folder').html(data);
}
});
}
}
}
}
谢谢大家!