Saad Awan
Saad Awan

Reputation: 163

pass a jquery window.width value to php variable

This is my javascript. I want to get jquery variable value to php variable in same page without using ajax. I used to print php variable but not show anything. I would be very grateful if anyone can help me.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

<script>
<?php echo 'alert($(window).width();';
$width= '$(window).width();';
echo $width;
?>

Upvotes: 0

Views: 238

Answers (1)

Imesh Chandrasiri
Imesh Chandrasiri

Reputation: 5679

PHP is a server side language and jQuery is a client side framework! When you load you php page, it first executes the server side code and then, it would execute your jquery code.

This would result in an empty string to be echoed. If you really want to get the client side window width, use an ajax function to send it your server. But then again I don't know what you are trying to achieve here.

Please review you application architecture.

Upvotes: 2

Related Questions