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:

  1. 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.

  2. 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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -