Tuesday, December 4, 2012

php – Turning $_GET $_POST $_SESSION into javascript

In my programs I often end up mixing php with javascript as

I need to check if a particular superglobal $_GET $_POST $_SESSION is set in a javascript condition.


This of course is bad for readibility and makes any future maintenance task more difficult.


I have recently discovered the simplicity of doing:



$_GET = <?=json_encode($_GET)?>
$_POST = <?=json_encode($_POST)?>
$_SESSION = <?=json_encode($_SESSION)?>


at the very beginning, and then:


(very simple condition as an example, they are often way uglier)



byid(\'example\').style.display = $_GET[\'example\'] ? \'block\' : \'none\'


instead of



byid(\'example\').style.display = <?=$_GET[\'example\']?> ? \'block\' : \'none\'


I would appreciate your thoughts on this method.






Rating: 4 out of 5 based on 3 ratings



The post php – Turning $_GET $_POST $_SESSION into javascript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/php-turning-_get-_post-_session-into-javascript.html

No comments:

Post a Comment