2016-09-30 98 views
-2

我有一个简单的问题,但无法找到该错误。也许你可以帮忙。这里是我的要求:阿贾克斯请求无函数

$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

在'else'情况下'$ Planes'是__empty__ –

+0

前嗯,我来到了空面我收到的JSON编码的回声 – Kavkus

+0

您收到'回声json'在另一个查询 –

回答

0

create_plane.php当$ _POST ['planeLMID']为空时,您尝试使用empty $ 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"; 
     } 
    } 
}