Search code examples
phpjqueryajaxhighchartshighmaps

Highmaps: PHP $_GET[] with JQuery Ajax: sending a value to the same page and capturing with PHP


I've built a map with PHP and Highmaps (from Highcharts libraries) which loads data from a SQL Server database. So far so good! But now I want to send a value from the map to another PHP page using Ajax since I want to send the name of the point clicked by the user.

series: {
    cursor: 'pointer',
    point: {
        events:{
            click:function(){
                var myVariable = this.name;
              $.get('my_page.php',{"brazil_state":myVariable});
            }
        }
    }
}

After doing this on the same page:

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

?>

And this would bring to me all the results that satisfy the condition of the query, but the parameter is not being parsed from JQuery Ajax to the PHP $_GET.

I've searched the answer, but I haven't found any yet.

Thanks in advance!!!


Solution

  • I've found a way to solve my question:

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

    Thank you, people!