开发者

How to get a value from a JavaScript variable to a PHP variable without AJAX, Jscript, HTML hidden field, or a cookie?

How to get a value from a JavaScript variable to a PHP variable without AJAX, Jscript, HTML hidden field, or a cookie ?

(from PHP to JavaScript: var javaScri开发者_运维百科ptVar = "<?php echo $someVar; ?>"; ) So is there nothing like that?

thanks


You can do it like in your example, but your javascript must either be inside a script tag which is in a PHP file, or in an external 'js' file that you save with a php extension.

Or, you can set your server up so that all files with a 'js' extension also get parsed by PHP, but that's probably more than overkill.

However, since the PHP will only be executed once before the file is returned to the client, there's no way to make that dynamic. If your objective is to do something simple with data that resides on the server (and more than likely will not change between page accesses) it won't be too horrible to accomplish what you want to do that way.


There is no way to get a Javascript value from PHP, because the response line goes from server to browser, never the other way around. AJAX is your best bet in this case.


There is nothing like that. The data needs to be transfered to the server, either by a form variable or a url variable. Either with an AJAX request or a normal request. I never thought about doing it with a cookie, but I guess that is an option too.


No.

PHP is a server sided language, javascript is a client sided language.

In order for PHP to receive information, you must talk to the server. The only way to do so is to submit a form, or use AJAX.


Short answer is you can't. There are two main ways to send content to the server from the client, which are cookies and submitted data (either posted or through the querystring). If you were so inclined you could add it to a request header but that is plain obscure and would require an AJAX request.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜