javascript - how to pass js integer value as integer in PHP? -
this question has answer here:
- how pass javascript variables php? 12 answers
<script type="text/javascript"> var int_val = 111; </script> <?php $js_int_val_in_php ='<script>document.write(int_val);</script>'; echo $js_int_val_in_php; // 111 echo '<br>'; echo gettype($js_int_val_in_php); // string // want integer // settype(); not help!! ?>
anyone has idea how pass js integer value integer in php?? love jquery in situation, please no jquery suggestion.
you confusing server-side variables client-side variables,
you need data server, otherwise server knows variable name, string
<script> var int_val=111; function doajax() { var xmlhttp; xmlhttp=new xmlhttprequest(); xmlhttp.open("get","index.php?v="+int_val,true); xmlhttp.send(); } </script> <a href="javascript:doajax();">click here send data server</a> <?php $int_val='' if (isset($_get['v'])) {$int_val=intval($_get['v']);} //now can access `int_val` after js function ran ?>
Comments
Post a Comment