【发布时间】:2017-03-07 02:50:38
【问题描述】:
我使用 jquery $.post 函数发布到我的本地服务器。它正确发布,我看到 $_POST 数组中的值。但是当我在网站上在线上传相同的代码时,$_POST 返回空。不知何故, 'name' 变量甚至没有被发送过来?我错过了什么?
这里是 jquery/javascript 方面:
$("#box").keyup(function( event ) {
//Simple test to see if it gets to the
//file.
$.post( "test-file.php", { name:"John"}, function() {
alert( "success" );
})
.done(function(data) {
//Checking the respones from the file
alert( "second success: "+data );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
});
下面是 test-file.php 文件的作用:
<?php
//Checking to see if I get to the
//file
echo "TEST:";
//Checking to see whats inside the post
var_dump($_POST);
?>
【问题讨论】:
-
您可能需要仔细检查 test-file.php 的路径
-
始终在浏览器中使用
F12打开开发控制台,然后查找选项卡网络以查看 ajay 制作时的实际情况。 -
@Cruiser 我收到了来自 test-file.php 的回复。所以这意味着它正在达到。
标签: javascript php jquery