簡體   English   中英

Angular的$ http.post到PHP空$ _POST

[英]Angular's $http.post to PHP empty $_POST

我有以下情況,我有一個名為contact的Angular變量,它是一個具有以下成員的JSON對象:

  • 信息
  • 名稱
  • 電話
  • 電子郵件

console.log(contact)並記錄了正確的信息,但是一旦發送, $_POST['contact']導致一個空數組。 我正在閱讀,發現$_POST['contact']不會像是jQuery的http請求那樣被填充。 所以我將其固定為以下內容:

$params = json_decode(file_get_contents('php://input'),true);
print_r($params);

這是Angular函數:

$scope.submitForm = function(contact){
        console.log(contact);
        $scope.clearContactFormData();
        return $http.post('http://localhost/cpr_courses/app/methods/contact.php', contact).success(function(data){
            Materialize.toast(data, 4000);
        });
    }

仍然print_r($params)為空。 我不知道還有什么事。 有什么幫助嗎?

編輯

console.log()輸出以下內容:

Array[0]
email
:
"asd@asd.asd"
length
:
0
message
:
"rubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOB"
name
:
"rubAWREIUVBAERWOBNATEIOB"
phone
:
"13345678"

這是網絡標簽圖片:

響應頭

這是JSON對象的聲明:

$scope.contact = {};
$scope.onlyNumbers = /^[0-9]+$/;

稍后將其放在這樣的表單上:

<form method="post" class="form-sl" role="form" name="contactForm" ng-submit="submitForm(contact)" novalidate enctype="multipart/form-data">

之后,在每個字段上都這樣:

<input type="email" name="email" id="email" ng-model="contact.email" autocomplete="off" ng-maxlength="50" length="50" required/>

這樣可以嗎?

$_POST超全局變量是一種PHP商品,用於自動解碼HTML表單發送的典型POST請求的正文。 換句話說,它期望Content-Type請求標頭中的這些值之一:

  • application/x-www-form-urlencoded
  • multipart/form-data

由於您具有application/json ,因此它保持為空。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM