Highmaps: PHP $_GET[] with JQuery Ajax: 将值发送到同一页面并使用 PHP 捕获
Highmaps: PHP $_GET[] with JQuery Ajax: sending a value to the same page and capturing with PHP
我用 PHP 和 Highmaps(来自 Highcharts 库)构建了一张地图,它从 SQL 服务器数据库加载数据。到目前为止,一切都很好!但是现在我想使用 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);
}
?>
这会给我带来所有满足查询条件的结果,但参数没有从 JQuery Ajax 解析到 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);
}
});
}
}
}
}
谢谢大家!
我用 PHP 和 Highmaps(来自 Highcharts 库)构建了一张地图,它从 SQL 服务器数据库加载数据。到目前为止,一切都很好!但是现在我想使用 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);
}
?>
这会给我带来所有满足查询条件的结果,但参数没有从 JQuery Ajax 解析到 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);
}
});
}
}
}
}
谢谢大家!