javascript - Passing JS variable to PHP -
i trying pass js variable php , have php echo js variable back. keep getting empty null string. 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); ?>
you should separate php code different file , should 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 above code 123.html , keep below code in xrege.php
<?php $ud = $_post['ud']; echo json_encode($ud); ?>
Comments
Post a Comment