2016-09-30 4 views
-2

간단한 문제가 있지만 오류를 찾을 수 없습니다. 어쩌면 당신이 도울 수 있습니다. 여기 내 요청입니다 :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

수정'$ Planes'은 __empty__ –

+0

내가 json으로 인코딩의 에코를받을 빈 비행기에 와서 잘 전에 – Kavkus

+0

당신은받을 귀하의'에코 json' 다른 쿼리에서 –

답변

0

create_plane.php 파일 $ _POST [ 'planeLMID']이 비어있는 경우 빈 $ Planes 배열을 사용하려고합니다.

그래서 POST로 데이터를 수신하는지 여부에 관계없이 매번 $ 평면 배열을 가져와야합니다. 참조가 else` 경우`에 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"; 
     } 
    } 
}