Save the integer of jscript as a php index

This question already has an answer here:

  • What is the difference between client-side and server-side programming? 5 answers

I’m trying to get the browser’s width and then compare it as a php variable, but it is saving it as a string, I tried parsing it to another variable but it only returns 0.

$tam='var j= $(window).width(); document.write(j)';

I’m doing the parsing like this:

$ntam=(int) $tam;

You can’t save a javascript value into a php variable directly. But you can….Put the php value into a javascript variable and use that for making your changes using javascript.

<?php  echo 'var jVar = "$phpVar";'; ?>

If you are importing your script from a js file you will want to add this before your import or course.

And I’m not sure what you’re trying to accomplish but if you need a js value you can always send that value using an ajax Request…

var ajax = new XMLHttpRequest();
var form  = new FormData();

On the server side code, which in this example is processJSWindowSize.php, you can have something along the lines of

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Save the integer of jscript as a php index

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录