Passing Js Variable To Php
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){
Solution 1:
you should separate php code into a different file and it should be working.
if(u){
var dt = {'ud':u};
console.log(dt);
$.post('xrege.php', dt, function(r){
console.log(r);
console.log(typeof r);
},"json");
}
name the above code like 123.html and keep the below code in xrege.php
<?php$ud = $_POST['ud'];
echo json_encode($ud);
?>
Post a Comment for "Passing Js Variable To Php"