0

I am sending a javascript variable to a PHP document via ajax. The PHP doesn't recognise that the sent variable is set using the isset() function in a conditional statement. The conditional statement returns false and the variable that I want to declare doesn't get defined at all. Any ideas how to fix it?

I don't think that the javascript code is responsible for the error, because the function that sends the data to the PHP document returns a statement when the transfer is succesful.

javascript code:

function AddMarker(addDescription,addId)
  {
    var marker = new google.maps.Marker(
    {
      position: {lat: arr[0], lng:arr[1]},
      map: map,
      title: 'Click to zoom',
      id: addId,
    });
    markers.push(marker);
    google.maps.event.addListener(marker, 'click', function(){
        infowindow.close(); // Close previously opened infowindow
        infowindow.setContent( "<div id='infowindow'>"+ addDescription +"</div>"+"<div id='iddiv'>Id: "+addId+"</div>"+"<button onclick='sendToEdit("+marker.id+")'>edit</button>");
        infowindow.open(map, marker);
      });
  }
function sendToEdit(recId)
{
  window.open("edit.php");
  $.ajax({
    url: "edit.php",
    method: "post",
    data: {recId:recId},
    success: function(res)
    {
      console.log(recId+" transfer successful");
    }
  });
}

php code:

<?php
if (isset($_POST['recId']))
{
    $ID = $_POST['recId'];
}
else
{
    echo "data isn't set";
}
?>

this is how i display the $ID variable:

<input type="text" id="txt" value="<?php echo $ID ?>" style="width:50%; height:50%;">

I get an Undefined variable error for $ID most likely because the "if" statement returns false.

kishetate
  • 21
  • 4

0 Answers0