简体   繁体   English

使用Confirm()在Javascript中执行PHP代码

[英]Executing PHP Code in Javascript with Confirm()

I am trying to use javascript's confirm function to set my php variable $continue based on the confirm click. 我试图使用javascript的确认函数来设置我的PHP变量$ continue基于确认点击。 I feel like the code below should work, but $continue is always false. 我觉得下面的代码应该可行,但$ continue总是假的。

    <script type="text/javascript">
    <!--
    var answer;
    answer = confirm("Do you want to continue?");
    if (answer) { <?php $continue = true; ?> }
    else { <?php $continue = false; ?> };

    // -->
    </script>

Any help is always appreciated! 任何帮助总是受到赞赏!

php is server side, javascript is client side. php是服务器端,javascript是客户端。

if you need to change something via javascript do this using ajax. 如果您需要通过javascript更改某些内容,请使用ajax执行此操作。 but you need keep this in your mind: the php just write html and process http requests. 但你需要记住这一点:php只需编写html并处理http请求。 all of the interaction in the client side who will change some state in the server must perform a http request. 客户端中将更改服务器中某些状态的所有交互必须执行http请求。

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

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