need to pass variable from javascript to php without refreshing or submitting -
i need screen size of visitors. use javascript.
<script> var screenwidth = window.screen.width, screenheight = window.screen.height; alert (screenwidth); </script> <?php $value = $_post['val']; echo "i got value! $value"; ?>
now, need pass value in php code, without refreshing page , don't want click on submit button
high level: browser sends request server, server responds (in case dynamically generated html), browser parses html , makes , dom. can script against dom @ point javascript.
usually time you're in browser scripting in javascript, can't pass value php without making new request.
at least 2 options make request:
if want send data server without page refresh, you're looking ajax. you'll have response dump dom. you'd have on every page reload.
another option in case: since want serve different html based on users screen since on multiple requests can set cookie javascript. every subsequent request contain cookie can read php. write on technique here: https://css-tricks.com/server-side-mustard-cut/
Comments
Post a Comment