Pass a JS variable to a PHP variable

You can use jQuery ajax for this, but you need to create another script that save on your database:

<script>
$.ajax({
    url: "save.in.my.database.php",
    type: "post",
    dataType:"json",
    data: {
        lugar: results[0].geometry.location
    },
    success: function(data){
        alert('saved');
    },
    error: function(){
        alert('error');
    }
});
</script>

“save.in.my.database.php” receives a $_POST['lugar'] and you can save on your database.

Leave a Comment