[英]Nothing in $_POST (Http request / Angular / PHP)
我遇到一個簡單的問題,但是在Web上找不到任何答案。 所以,這是我的代碼
const URL = 'http://(...)/scripts/Fiabilisation_Unique.php';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type: application/json'
'reportProgress': 'true'
})
(...)
onClickAdresse(f : NgForm){
var adresse : Adresse= (f.value);
console.log(adresse); //{adresse : "just a french adresse"}
this.http.post(URL, adresse, httpOptions).subscribe(
(event) => {
this.temp=(event); // handle event here
},
() => {
console.log("Observable done ! ");
}
);
}
但是在我的文件“ Fiabilisation_Unique.php”中,當我嘗試一個簡單的: print_r($_POST);
它會向我輸出: Array( )
我很確定我的問題不會那么復雜,但是我只是不知道問題出在哪里。 我也知道答案不應該那么遠,但是...
先感謝您 :)
您的HttpOptions
不正確。 引號錯誤和reportProgress放錯了位置:
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
},
reportProgress: true
});
但是,如果啟用reportProgress
,則訂閱將從HttpEventType.Sent
發送到HttpEventType.Done
接收多個事件。 但是我想這就是你想要的:)
好的,大家,我終於找到了答案。 不出所料,這真的很容易。
我只添加一個$angularJSData = json_decode(file_get_contents("php://input"));
在我的PHP代碼中。
感謝大家 !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.