I am trying to pass a JS variable to PHP and have PHP echo the JS variable back. I keep getting an empty null string. What am I doing wrong?
function(u){
if(u){
var dt = {'ud':u};
console.log(dt);
$.post('xrege.php', dt, function(r){
console.log(r.responseText);
console.log(typeof(r.responseText));
});
}
});
<?php
$ud = $_POST['ud'];
echo json_encode($ud);
?>
ris.uis a boolean in this case. 2) You're trying to asignuto nothing. The correct syntax would be{ud: u}without the quotes. Quote from the jQuery api:$.post( "test.php", { name: "John", time: "2pm" } );3) Don't mix Javascript with jQuery. It should beconsole.log(r);