Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send javascript variable to php mysql [duplicate]

I am trying to insert javascript varaible to php mysql, but it is not inserting. it is inserting as <javascript>document.write(window.outerWidth); </javascript> x <javascript>document.write(window.outerHeight); </javascript>. but the result is 1366 x 728

What should I do?

<?php
$width = " <script>document.write(window.outerWidth); </script>";
$height = " <script>document.write(window.outerHeight); </script>";
$xex = " x ";
$resulteee = "$width $xex $height";
echo $resulteee;
?>
like image 836
only chande Avatar asked May 31 '26 12:05

only chande


1 Answers

AJAX is a good solution to your problem :

<script type="text/javascript">
     function call_ajax () {
           var width = window.outerWidth;
           var height = window.outerHeight;

           var xmlhttp = new XMLHttpRequest();

           xmlhttp.onreadystatechange = function() {
                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                     document.getElementById("abc").innerHTML = xmlhttp.responseText;
                 }
             }
             xmlhttp.open("POST", "a.php?height="+height+"width="+width, true);
             xmlhttp.send();
        }
    </script>

and on the page a.php, you can echo your variables to get the output like this :

<?php
echo $_POST['height'];
echo $_POST['width'];
die;
like image 148
Nehal Avatar answered Jun 03 '26 00:06

Nehal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!