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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -