Advertisement
Guest User

ajax return

a guest
Oct 1st, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //HERE IS THE GETGEOY.PHP (getgeoX is just the same...
  2.  
  3. <?php
  4.  
  5.     include '../functions.php';
  6.     session_start();
  7.     if(isset($_POST['id'])){
  8.        
  9.         $db = connectToDb('julos');
  10.         $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
  11.         $db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
  12.         $id = $_POST['id'];
  13.         $getGeo = $db->prepare("SELECT Y(geo_position) AS y FROM geo WHERE geo_id = :id");
  14.         $getGeo->execute(['id'=>$id]);
  15.         if (!$getGeo->rowCount()) {
  16.             echo ("false");
  17.         }
  18.        
  19.         $y = $getGeo->fetchColumn(0);
  20.         $getGeo->closeCursor();
  21.  
  22.         echo json_encode($y);
  23.     }else{
  24.         echo "ERREUR ID NOT SET";
  25.     }
  26.  
  27. ?>
  28.  
  29. //////////////////////////////////////////////////////////////////////////////////////////////////
  30.  
  31. // here is the problematic JS
  32.  
  33. function getGeoX(id){
  34.         return $.ajax({
  35.             type : 'POST',
  36.             url : './php/utils/getGeoX.php',
  37.             data : {'id':id},
  38.             dataType : 'json',
  39.             error : function(response){
  40.                 console.log("ERROR GET X "+response.responseText);
  41.             },
  42.             success : function(response){
  43.                 console.log("SUCCESS GET X "+response);
  44.  
  45. //THIS DISPLAYS THE RIGHT DATA WHICH IS A NUMBER !!!
  46.  
  47.             }
  48.         });
  49.     }
  50. function getGeoY(id){
  51.         return $.ajax({
  52.             type : 'POST',
  53.             url : './php/utils/getGeoY.php',
  54.             data : {'id':id},
  55.             dataType : 'json',
  56.             error : function(response){
  57.                 console.log("ERROR GET Y "+response.responseText);
  58.             },
  59.             success : function(response){
  60.                 console.log("SUCCESS GET Y "+response);
  61.  
  62. //THIS DISPLAYS THE RIGHT DATA WHICH IS A NUMBER !!!
  63.  
  64.             }
  65.         });
  66.     }
  67.  
  68. //THE PROBLEM IS IN THE NEXT PART :
  69.  
  70. $("body").on("click",".gmLocate",function(){
  71.         $("#idGeo").val(this.id);
  72.         var lat = (getGeoX(this.id));
  73.         var lng = (getGeoY(this.id));
  74.         console.log("DISPLAY LAT : "+lat);
  75.  
  76. //THIS CONSOLE LOG DISPLAYS : DISPLAY LAT : [object Object]
  77.  
  78.         console.log("DISPLAY LNG : "+lng);
  79.  
  80. //THIS CONSOLE LOG DISPLAYS : DISPLAY LNG : [object Object]
  81. //I have to get my value back... when i check what is in this object, i see this in the log :
  82. //         readyState 4
  83. //         responseJSON 50.244641280083
  84. //         responseText "50.244641280083"
  85. //         status 200
  86. //         statusText "OK"
  87. // ...
  88.         .......................................
  89.         .......................................
  90.         .......................................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement