2014-12-23 3 views
0

내 푸른에 복잡한 JSON 개체를 게시하도록하겠습니다 PHP 5.4 사용 AngularJS와 IIS를 실행에 // 입력이 비어 :PHP : 푸른

var request = $http({ 
    method: "post", 
    url: "/php/mail.php", 
    data: $scope.contactForm, 
    headers: { 
     'Content-Type': 'application/x-www-form-urlencoded' 
    } 
}); 

내 PHP 스크립트는이 두 가지 라인으로 구성

$data = json_decode(file_get_contents("php://input")); 
print_r($data); 

POST 된 데이터를 읽으려고 할 때 모든 배열 ($_POST, $_REQUESTphp://input)은 비어 있습니다. POST 데이터를 삭제하고 $_SERVER['CONTENT_TYPE']이 반향하는 'application/x-www-form-urlencoded'이 반환되는 리디렉션이 없습니다.

+0

Azure가 아닌 서버에서 작동합니까? –

답변

0

PHP에서 JSON이 필요하므로 Content-Type이 잘못되었습니다. 또한 데이터를 문자열로 변환해야하므로 AngularJS 코드는 다음과 같이 표시됩니다.

var request = $http({ 
    method: "post", 
    url: "/php/mail.php", 
    data: JSON.stringify($scope.contactForm), 
    headers: { 
     'Content-Type': 'application/json' 
    } 
});