Ajax请求发布没有功能

时间:2016-09-30 15:24:42

标签: php jquery angularjs ajax

我遇到了一个简单的问题,但找不到错误。也许你可以帮忙。这是我的要求:

$http({
    url:'api/create_plane.php',
    method: "POST",
    data: {
        planeKey: $scope.editKey,
        planeSQLID: $scope.editSQLID,
        planeLMID: $scope.editLMID,
        planeAFID: $scope.editAFID,
        planeVersion: $scope.editVersion,
        planeLot: $scope.editLot,
        planeStation: $scope.editStation                   
    },
    dataType: 'json'
}).success(function(data, status, headers, config) {
    console.log(data);
}, function(response) {
    console.log(response);
});

这是我的Php文件:

$Planes = array();
$MAX_PLANES = 45;

if (empty($_POST['planeLMID'])) {
    for ($i = 1;$i < $MAX_PLANES;$i++) {
        if (checkSQL($i)) {
            $Planes[$i] = new createPlane($i,$db);
        }
    }
    echo json_encode($Planes);   
}
else {
    for ($i = 1;$i < $MAX_PLANES; $i++) {
        if ($Planes[$i]['planeSQLID'] == $_POST['planeSQLID']) {
            echo "HALLO";
        }   
    }
}

但我不会在任何时候看到"Hallo"。我需要你的帮助。

1 个答案:

答案 0 :(得分:0)

create_plane.php 文件中,当$ _POST ['planeLMID']为空时,您尝试使用空的$ Planes数组。

因此无论您是否通过POST接收数据,每次都需要获取$ Planes数组。 请参阅修改后的 create_plane.php

$Planes = array();
$MAX_PLANES = 45;

for ($i = 1;$i < $MAX_PLANES;$i++) {
    if (checkSQL($i)) {
        $Planes[$i] = new createPlane($i,$db);
    }
}
echo json_encode($Planes);   

if(!empty($_POST['planeLMID'])) {
    for ($i = 1;$i < $MAX_PLANES; $i++) {
        if ($Planes[$i]['planeSQLID'] == $_POST['planeSQLID']) {
            echo "HALLO";
        }   
    }
}
相关问题