简体   繁体   English

PHP从JavaScript onClick(HTML)获取变量?

[英]PHP get variables from JavaScript onClick (HTML)?

I need to get variables from a html link, this is the link and when it is clicked it shows the popup window. 我需要从html链接获取变量,这是该链接,单击该链接时会显示弹出窗口。

<a href='#' onclick=\"show('poruka');var idporuke=$porid; \">Pogledaj<a>

And I have var idporuke=$porid; 我有var idporuke=$porid; which is working like a charm. 就像魅力一样运作。 But I need to pass that variable to php script? 但是我需要将该变量传递给php脚本? I can't use GET or POST methods. 我不能使用GET或POST方法。

html html

<img src="about:blank" id="fake_request" style="position:absolute; top: -20px;left:-20px;width:1px;height:1px;" />

<a href='#' onclick=\"show('poruka');var idporuke=$porid; document.getElementById('fake_request').src='/myPhpScript.php?idporuke='+idporuke+';">Pogledaj<a>

something like this 像这样的东西

尝试这个:

<a href='#' onclick="show('poruka');var idporuke=$porid;">Pogledaj<a>

It sounds like you are trying to pass a browser side variable to a server side script. 听起来您正在尝试将浏览器端变量传递给服务器端脚本。 PHP does all of its processing, then the HTML/Javascript takes over. PHP完成所有处理,然后由HTML / Javascript接管。 The only methods you have for passing a variable through from browser to server are via either a page refresh or Javascript AJAX. 将变量从浏览器传递到服务器的唯一方法是通过页面刷新或Javascript AJAX。 If you absolutely cannot use POST or GET, you could use Cookies (http://techpatterns.com/downloads/javascript_cookies.php) or Sessions...although I am pretty sure sessions are not supported in Javascript. 如果您绝对不能使用POST或GET,则可以使用Cookies(http://techpatterns.com/downloads/javascript_cookies.php)或Sessions ...尽管我很确定Javascript不支持session。 I would recommend using POST or GET depending on the variable size - Cookies come with a lot of limitations and conditions. 我建议根据变量大小使用POST或GET-Cookies具有很多限制和条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM