2016-09-30 9 views
-2

У меня есть простая проблема, но не могу найти ошибку. Может быть, вы можете помочь. Вот мой запрос:Ajax request Сообщение no function

$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 файл, который вы пытаетесь использовать пустой массив $ Planes, когда $ _POST ['planeLMID'] пуст.

Так что вам нужно каждый раз получать массив $ Planes независимо от того, получаете ли вы данные POST. См модифицирован 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"; 
     } 
    } 
}