我使用 jquery $.post 函数发布到我的本地服务器。它正确发布,我看到 $_POST 数组内的值。但是当我在网站上在线上传相同的代码时,$_POST 返回空。不知何故,'name' var甚至没有被发送过来?我缺少什么?
这是 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);
?>
最佳答案
您需要编写 php 页面的 url。
如果是 www.my_url.com/test-file.php 你需要这样写:
$.post( "www.my_url.com/test-file.php", { name:"John"}, function() {
alert( "success" );
}) .....
关于javascript - ajax $_POST 数组丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629769/