我对PHP比较陌生,所以如果我错过了一些明显的东西,请原谅我。
我在 Raspberry Pi 上建立了一个 Apache 服务器,并成功地用 PhpStorm 配置了 Xdebug,可以设置断点等。
我最初尝试的是一个基本的html表单,用Ajax POST请求来运行一个PHP文件来进行验证。它成功地发送了请求,因为PhpStorm在PHP文件中设置的断点处断裂,然而并没有出现 $_POST
在调试器中,只有 $_COOKIE
和 $_SERVER
.
如果有人有任何想法,将是非常感激。
html文件中的JavaScript。
$("#frmContact").on('submit',function (e) {
e.preventDefault();
$("#mail-status").hide();
$('#send-message').hide();
$('#loader-icon').show();
$.ajax({
url: "contact.php",
type: "POST",
dataType: 'json',
data: {
"name": $('input[name="name"]').val(),
"email": $('input[name="email"]').val(),
"selection": $('input[name="selection"]').val(),
"content": $('textarea[name="formText"]').val()
},
success: function (response) {
$("#mail-status").show();
$('#loader-icon').hide();
if (response.type == "error") {
$('#send-message').show();
$("#mail-status").attr("class", "error");
} else if (response.type == "message") {
$('#send-message').hide();
$("#mail-status").attr("class", "success");
}
$("#mail-status").html(response.text);
},
error: function () {
}
});
});
php.ini文件(在树莓派上)
;XDebug
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_host=192.168.2.201
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.collect_params=4
xdebug.show_local_vars=on
xdebug.dump.SERVER=REQUEST_URI,DOCUMENT_ROOT,SCRIPT_FILENAME
xdebug.default_enable=1
请检查你的请求在浏览器的开发者工具的网络选项卡中的显示方式。
我问这个问题的原因是:有可能是你的请求没有正确通过,或者它没有发送数据(这将解释为什么你看不到你的请求。$_POST
变量: PhpStorm可以隐藏这种空的全局变量(在IDE的Debug工具窗口中检查选项)。
你的网络浏览器应该会告诉你到底发送了什么,以及是否有任何重定向等(例如,POST数据通常在302重定向时丢失,请求动词应该改为GET)。如果请求中没有POST数据,那么一定是收集POST数据的JS代码有问题。