我有一个简单的函数,它将多个输入的值和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"
}
}
}
答案 0 :(得分:1)
$timeBlockLocation = $connection->real_escape_string($_POST["dataObject"][0]["timeBlockLocation"]);