Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
$\u POST中没有任何内容(Http请求/Angular/PHP)_Angular_Typescript - Fatal编程技术网

$\u POST中没有任何内容(Http请求/Angular/PHP)

$\u POST中没有任何内容(Http请求/Angular/PHP),angular,typescript,Angular,Typescript,我被一个简单的问题困住了,但我在网上找不到任何答案。这是我的代码 const URL = 'http://(...)/scripts/Fiabilisation_Unique.php'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type: application/json' 'reportProgress': 'true' }) (...) onClickAdresse(f : NgForm){ var a

我被一个简单的问题困住了,但我在网上找不到任何答案。这是我的代码

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 ! ");
    }
  );
}
但是在我的文件'fialization\u Unique.php'中,当我尝试一个简单的:
print\r($\u POST);
它会打印我:
Array(
)

我很确定我的问题没有那么复杂,但我只是不知道问题是什么。我也知道答案不应该太远,但


提前感谢:)

您的
HttpOptions
不正确。错误的报价和报告进度错误:

const httpOptions = {
  headers: new HttpHeaders({
   'Content-Type': 'application/json'
  },
  reportProgress: true
});

但是如果您启用
reportProgress
,订阅将从
HttpEventType.Sent
接收多个事件到
HttpEventType.Done
。但我想这就是您想要的:)

好了,各位,我终于找到了答案。正如预期的那样,这真的很容易

我只是添加了一个
$angularJSData=json\u decode(file\u get\u contents(“php://input"));
在我的PHP代码中


谢谢大家!

this.temp=eventYes,但它并没有改变我的问题:)您能发布表单的tempate吗?

Lancer l'Le ligibilité
您确定post会返回一些内容吗?这是一种最佳做法,但并不总是这样。有些webapi会返回新对象,有些会返回id,返回一些de-url。console.log(event)报告什么?好了,那么console.log(event)的响应是:{type:0}{type:1,loaded:31,total:31}httpheaderrresponse{headers:HttpHeaders,status:200,statusText:“Ok”,url:,Ok:true,}headers:HttpHeaders{normalizedNames:Map(0),lazyUpdate:null,lazyInit:ƒ}ok:truestatus:200statusText:“ok”类型:2url:“http://(…)/scripts/fialization_Unique.php”proto:HttpResponseBase{type:3,loaded:1312,total:1312}