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

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

node.js - Express and Redis - If session exists for this user, don't allow access -