jQuery发布数据部分发送给PHP

时间:2015-05-08 05:03:19

标签: javascript php jquery ajax

我有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工作正常。

2 个答案:

答案 0 :(得分:2)

有一个错字。它应deletedImageGUIDs deleteImageGUIDs -

$deletedImageGUIDs = isset($_POST["deletedImageGUIDs"])?$_POST["deletedImageGUIDs"] : array();
timeline: { groupByRowLabel: false }

答案 1 :(得分:1)

使用以下,你有错字。

$deletedImageGUIDs = isset($_POST["deletedImageGUIDs"])?$_POST["deletedImageGUIDs"] : array();

它不是deleteImageGUIDsdeletedImageGUIDs