我有两个文件,第一个是a.php其次是b.php(弹出窗口)
在A中.php我通过Ajax发布数据
$.post("b.php",{cat:"hello"},function(result){
console.log(result);
});
在 B 中.php我正在使用
$cat = $_POST['cat'];
echo $cat;
在 a.php 的 DOM 中,显示"hello",但在 b.php 中显示为空白。 为什么???
在一个.php我正在使用
$('div#showrqmt').on('click',function(){
$.post("b.php",{cat:"hello"},function(result){
console.log(result);
});
});
<div class="upbtntopmain uploadaudio" href="javascript:void(0)" id="showrqmt"><a class="pnkbtnb_n">Show Requirments</a></div> (this will popup b.php)
在 ajax 的响应文本中,显示帖子数据("hello")但不在 php 中
在 B 中.php我使用
$cat = $_REQUEST['cat']; // not working
$cat = $POST['cat']; //not working
echo $cat // for both case not working...
如果你的意思是你在浏览器中访问 b.php,那么它将是空白的,因为你发出的是 GET 请求而不是 POST 请求。
您可以更改$cat = $_REQUEST['cat'];
,如果您在 URL 中提供猫,这将回显猫,例如 b.php?cat=hello
但是如果您想将其保留为POST请求,那么您将无法仅通过浏览器执行此操作。
请参阅 HTTP 方法:GET 与 POST
尝试添加数据类型 - 文本。见 http://api.jquery.com/jquery.post/