passing variable from javascript to a php within same function -


this question has answer here:

i facing issue regarding passing javascript variables php within same function. code looks this

 else if(msg_type[i] == 'code' ){     var code_action = 'test';     <?php     function foobar_func(){     return "<script>document.writeln(action[i]);</script>";     }     add_shortcode( 'foobar', 'foobar_func' );     ?> 

}

what doing passing code_action variable of javascript , returning function without using ajax or jquery...is there possible method so...??

any possibilities appreciated. thank you

when make request invoke page, <?php ?> block executed in server. creates processed output in web page (in code) , send browser. browser executes <script> </script> blocks.

i hope understand passing variables <script></script> <?php ?> impossible since latter happened in past.

but can use other way around trying pass variables php js.

when write

<?php    $fromserver = "from php";     echo "<script> var fromserver = " . $fromserver . " </script> ?> 

.. passes data php js.

you can, however, use http post or method pass data js php used in next session.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -