我有javascript代码获取ID数组,然后使用ajax将它们发送到PHP。出于某种原因,我发送的3个数组中,第一个从未发送,所以我总是在PHP中得到一个空数组,即使我在调用$.post()
使用Javascript:
$.post(
"ajax.php",
{
deletedImageGUIDs: deletedImageGUIDs
,imageGUIDs: imageGUIDs
,categoryGUIDs: categoryGUIDs
},
function(data, status) {
if (status == "success") {
alert(data);
deletedImageGUIDs = [];
imageGUIDs = [];
categoryGUIDs = [];
}
else {
alert("There was an error saving changes");
}
}
);
ajax.php:
if(!($_SERVER["REQUEST_METHOD"] == "POST")){
die("Request Error");
}
$deletedImageGUIDs = isset($_POST["deleteImageGUIDs"])?$_POST["deletedImageGUIDs"] : array();
$imageGUIDs = isset($_POST["imageGUIDs"])?$_POST["imageGUIDs"] : array();
$categoryGUIDs = isset($_POST["categoryGUIDs"])?$_POST["categoryGUIDs"] : array();
$deletedImageGUIDs
始终为空数组,而$imageGUIDs
和$categoryGUIDs
工作正常。
答案 0 :(得分:2)
有一个错字。它应deletedImageGUIDs
deleteImageGUIDs
-
$deletedImageGUIDs = isset($_POST["deletedImageGUIDs"])?$_POST["deletedImageGUIDs"] : array();
timeline: { groupByRowLabel: false }
答案 1 :(得分:1)
使用以下,你有错字。
$deletedImageGUIDs = isset($_POST["deletedImageGUIDs"])?$_POST["deletedImageGUIDs"] : array();
它不是deleteImageGUIDs
,deletedImageGUIDs
。