我有一个简单的函数,它将多个输入的值和 id 编译到一个对象中,然后将它们传递给 AJAX 函数。不幸的是,我无法正确发布数据。处理页面肯定被调用并且变量使它成为js(对象在控制台中看起来是正确的),但是所有变量在处理页面上似乎都是空白的。
脚本:
$("#" + buttonId).find(".submitValue").each(function() {
inputId = $(this).attr("id").replace(buttonId + "-", "");
inputValue = $(this).val();
var data = {};
data[inputId] = inputValue;
dataObject.push(data);
});
$.post(
'ajax/' + buttonId + '.php',
{
'nextForm': formNumber,
dataObject: dataObject
},
function (response) {
$("#" + buttonId).append(response);
}
);
相关的 php 处理页面(变量比这多得多,但看起来都一样 - 本示例中的 id 为“timeBlockLocation”、“appointmentAddress1”、“appointmentAddress2”) - 已创建连接
$nextForm = $connection->real_escape_string($_POST["nextForm"]);
$timeBlockLocation = $connection->real_escape_string($_POST["timeBlockLocation"]);
$appointmentAddress1 = $connection->real_escape_string($_POST["appointmentAddress1"]);
$appointmentAddress2 = $connection->real_escape_string($_POST["appointmentAddress2"]);
这是 $_POST 处理页面上的 var_dump:
array(2) {
["nextForm"]=>
string(1) "6"
["dataObject"]=>
array(3) {
[0]=>
array(1) {
["timeBlockLocation"]=>
string(1) "1"
}
[1]=>
array(1) {
["appointmentAddress1"]=>
string(4) "TEST"
}
[2]=>
array(1) {
["appointmentAddress1"]=>
string(5) "TEST2"
}
}
}