开发者

Is it possible to use JavaScript's variable in PHP? [duplicate]

This question already has answers here: 开发者_如何转开发 Closed 11 years ago.

Possible Duplicate:

Access a JavaScript variable from PHP

theVariable = String.fromCharCode(theVariable).toLowerCase();

is it possible to use theVariable in PHP codes ? How?


Not really... you can send it to a PHP script using AJAX or an HTML form. I strongly recommend you get a clearer understanding of what JavaScript is vs. PHP, particularly what it means that JavaScript runs on the client-side (i.e. in the browser), and PHP runs server-side.


Only if the the variable is sent via ajax to a PHP page. You see PHP is executed first, then the page is served to the client. Then the client executes the javascript. So the javascript is executed long after the PHP has been executed.


To use a variable that is in JavaScript in PHP, you have to send an Ajax request to a PHP page passing that variable in. This probably isn't the effect you're looking for.

JavaScript executes on the viewer's computer. PHP executes on the server. To send a JavaScript variable to PHP, you need to send some packet of information from the client to the server. This is done as a GET/POST request.


The only way to pass a variable from JavaScript to PHP is to pass it by an AJAX call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜