将jQuery值分配给php变量 [英] Assign jquery value to php variable

查看:93
本文介绍了将jQuery值分配给php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在同一页面中,我在单击按钮的同时设置了jquery值.我想将值传递给同一页面中的php变量,而无需提交表单.

In same page i set the jquery value while click the button. i want pass the value to php variable in same page without form submitting.

<input type="button" name="next"  class="next btn btn-primary" value="Proceed To Checkout Page" />

jQuery

$(".next").click(function(){
       <?php $var1="1";?>
 }

同时检查php值

<?php if(isset($var1)){
     echo $var1;
 }else{
    echo "NULL";
   }?>

每次我都得到空值.我在哪里弄错了. ps:我无法发送ajax调用来获取值

Every time time i got the null value. Where i getting mistake. Ps: I cant able to send the ajax call to get the value

推荐答案

您根本无法做到这一点,您需要了解客户端/服务器端编程之间的区别,不能将Javascript值分配给PHP变量,是的,但是您可以分配PHP对您的JavaScript有价值.

You simply cannot do that, you need to understand the difference between client/server side programming, you cannot assign Javascript value to PHP variable, yea but you can assign PHP value to your javascript.

您可以使用cookie来实现这一目标.

You can use cookies to achieve this.

在Java语言中:

<script type="text/javascript">
    document.cookie = "var1=1";
</script>

在PHP中

<?php 
   $phpVar =  $_COOKIE['var1'];
   echo $phpVar;
?>

这篇关于将jQuery值分配给php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆