【发布时间】:2014-09-20 12:56:45
【问题描述】:
我的问题如下(问题已更新):
我有两页:
1.php 和 2.php
我正在尝试从 2.php 到 1.php获取一个 PHP 变量(在这种情况下是一个 SESSION 变量) > 通过 AJAX 请求。
这是1.php中的脚本
jQuery('#refresh').click(function(e){
e.preventDefault();
jQuery.ajax({
type:'POST',
url: '2.php',
data: { sessionVar: '<?php $PHPvariable ?>' },
success:function(response){
alert(sessionVar);
}
})
});
为了更好地理解,这个脚本是从1.php文件中调用的,以便正确地将PHP注入到js中。 如您所见,我正在尝试检索 2.php 中声明的 $PHPvariable 变量。
我做得对吗??
【问题讨论】:
-
请修正您的代码。那里没有sn-p。
-
不刷新当前页面。没办法,你应该用javascript。
-
是的,我知道了,但是怎么做? :)
-
你可以使用 js 来做见link
-
是的,因为你的问题是
I'm using wood to beat nails, but one nail is too big, and I cannot beat it enough to get there, I tried to beat them with a hammer, but unfortunately I couldn't manage, because I do not know how to use hammer. Maybe there's another way;不,你最好用锤子,而不是更重的木头。很难理解英语术语也是一件好事,因为你会在尝试理解这些术语的同时提高你的英语水平。所以,我会根据你想要找到解决方法而不是使用正确的工具来评判你
标签: php jquery ajax session-variables