0

我用 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);
  }

?>

这会给我带来满足查询条件的所有结果,但是参数没有从 JQuery Ajax 解析到 PHP $_GET。

我已经搜索了答案,但我还没有找到任何答案。

提前致谢!!!

4

2 回答 2

0

在第二个代码片段中,您引用了变量 $_GET['myVariable'],但是您在 ajax-request 中使用的变量的名称:

$.get('my_page.php',{"brazil_state":myVariable});

是“巴西国家”

于 2015-02-12T19:14:35.377 回答
0

我找到了解决我的问题的方法:

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);
          }
        });
      }
    }
  }
}

谢谢你们!

于 2015-02-13T17:59:59.197 回答