Pass JavaScript variables into PHP -


i want pass javascript variables php. know maybe impossible, try use window.location.href me php js variables, question don't want refresh when clicked video.

how can make don't refresh after click video?

html:

<!doctype html> <html lang="en">  <head>     <meta charset="utf-8">     <title>ueranalysis</title>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>     <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script>     <!--<script type="text/javascript" src="js/script.js"></script>--> </head>  <body>     <video id="video" src="source/maroon 5 - sugar.mp4" width="500px" height="400px"  onplay="starttime()" onpause="endtime()" controls>         <source src="source/maroon 5 - sugar.mp4">     </video>     <br>     <span id="timearea_start"></span>     <span id="timearea_end"></span>     <?php          echo ('<script src="js/script.js"></script>');      ?> </body> </html> 

js:

var vid = document.getelementbyid("video");  function starttime() {     console.log("startime:" + vid.currenttime)     var startime = document.getelementbyid("timearea_start").innerhtml;      var endtime = document.getelementbyid("timearea_end").innerhtml;       if (startime < endtime) {         console.log("startime:" + startime + "endtime:" + endtime + "," + "it" + "s" + " success!!");     }     var x = document.getelementbyid("timearea_start").innerhtml = vid.currenttime;     return window.location.href = "index2.php?vid=" + x; }  function endtime() {     console.log("endtime:" + vid.currenttime)     return document.getelementbyid("timearea_end").innerhtml = vid.currenttime }; 

if want pass php, without expecting response, can use jquery's ajax .get() function that: (i can see have jquery loaded in page anyway)

function starttime() {     console.log("startime:" + vid.currenttime)     var startime = document.getelementbyid("timearea_start").innerhtml;      var endtime = document.getelementbyid("timearea_end").innerhtml;       if (startime < endtime) {         console.log("startime:" + startime + "endtime:" + endtime + "," + "it" + "s" + " success!!");     }     var x = document.getelementbyid("timearea_start").innerhtml = vid.currenttime;     jquery.get("index2.php?vid=" + x); } 

this not reload page. index.php fill called in background.


Comments