Issue on Updating a jQuery Function by Ajax and PHP

Issue on Updating a jQuery Function by Ajax and PHP

Can you please help me to figure out how to pass ajax result into a jquery function.

I have a HTML Select options as:


  1. <?php
  2.     define('DB_HOSTNAME', 'xxxx'); 
  3.     define('DB_USERNAME', 'xxxx'); 
  4.     define('DB_PASSWORD', 'xxxx'); 
  5.     define('DB_DATABASE', 'xxxx'); 
  6.     $mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
  7.     if ($mysqli->connect_errno) {    die('Unable to connect!');}
  8.     else{
  9.         $query = 'SELECT DISTINCT projectID FROM DATA';
  10.         if ($result = $mysqli->query($query))   {
  11.             if ($result->num_rows > 0) 
  12.             {
  13. ?>  
  14.  <select id="selbycolo" class="selectpicker" data-live-search="true" data-size="5">
  15.  <option value="select">Select From List</option>
  16.  <?php      
  17.  while($row = $result->fetch_assoc()) {
  18. ?>      
  19.  <option value="<?php echo $row['projectID']; ?>"><?php echo $row['projectID']; ?></option>     
  20. <?php           
  21.         }
  22. ?>
  23. </select>
  24. <?php
  25.         }
  26.         else {  echo 'No records found!';}
  27.         $result->close();
  28.     }
  29.     else {echo 'Error in query: $query. '.$mysqli->error;}
  30. }
  31. $mysqli->close();
  32. ?>
then I have an jQuery Ajax method as:

  1. <script type="text/javascript">
  2.  $(document).ready(function(){
  3.  $('#selbycolo').change(function()
  4.         {
  5.             if($(this).val() == '') return;
  6.             $.get(
  7.                 'ecolo.php',
  8.                 { id : $(this).val() },
  9.                 function(data)
  10.                 {
  11.                   //$('#result').html(data);
  12.                  }
  13.             );
  14.         });

  15. });
  16. </script>
and finally I have the ecolo.php which I would like to populate some  Plots  into another jquery function. Here is what I have

  1. <?php
  2. define('DB_HOSTNAME', 'xxxx'); 
  3. define('DB_USERNAME', 'xxxx'); 
  4. define('DB_PASSWORD', 'xxxx'); 
  5. define('DB_DATABASE', 'xxxx'); 
  6. $mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
  7. $resultStr = '';
  8. $query = 'SELECT * FROM DATA WHERE projectID='.$_GET['id'];
  9. if ($result = $mysqli->query($query)) 
  10. {
  11.     if ($result->num_rows > 0) 
  12.     {

  13.         while($row = $result->fetch_assoc())
  14.         {


  15.         }

  16.     }
  17.     else
  18.     {
  19.         $resultStr = 'Nothing found';
  20.     }
  21. }
  22. echo $resultStr;
  23. ?>
now what I need to do is updating a jquery function

  1. 'Area 1': {
  2.                     latitude: 49.25,
  3.                     longitude: -123.10,
  4.                     tooltip: {
  5.                     content: "xzx"
  6.                     }
  7.            }

In this script

  1. <script>
  2. $(function () {
  3.     $(".maparea1").mapael({
  4.         map: {
  5.             name: "testmap",
  6.             defaultArea: {
  7.                 attrs: {
  8.                     stroke: "#90856f",
  9.                      "stroke-width": 0.7,
  10.                    fill: "url(img/svg.png)"
  11.                     }
  12.             }
  13.         },
  14.         plots: {
  15.         'Area 1': {
  16.                 latitude: 49.25,
  17.                 longitude: -123.10,
  18.                 tooltip: {
  19.                     content: "xzx"
  20.                 }
  21.             }
  22.         }

  23.     });
  24. });
  25. </script>

which  'Area 1'  is coming from  area  column ,  latitude  from  lat  ,  longitude  from  long  and content value from projectID. sorry this tools long but I tried to put every thing here by details.