【发布时间】:2018-06-06 09:59:00
【问题描述】:
我正在使用下面的 AngularJS 代码发布到 webhook。 POST 请求会通过 webhook。但是,它没有正文,因此没有返回任何数据。
$scope.addguest = function(guest){
//todo put guest to url
url = "https://requestb.in/18z1tu41";
item = {
'property_id':$scope.id,
'originator':guest.phone,
'guest_name':guest.name,
'check_out_date':guest.date
}
$('#exampleModalPhone').modal('hide');
$http.post(url, item, {headers: {'Content-Type': 'application/json'} }).success(function (data) {
$scope.data= data;
});
我是否在我的代码编写方式上遗漏了什么?是什么导致 POST 为空?
这不是与 CORS 相关的问题,因此不是重复的。
【问题讨论】:
-
哪个正文是空的....请求还是响应?什么版本的角度?
-
除非我误解没有请求/响应,否则它不是 API,而是 webhook。 webhook 收到的 POST 是空的。成功返回 HTTP 200 并且 webhook 确实收到了 POST,它只是有一个空正文。
-
看来你误会了。
$http发出 ajax 请求并在请求正文中发送您的数据并等待响应。如果响应正文为空,则为 api 问题 -
检查您的开发者控制台是否有错误。
Failed to load https://requestb.in/18z1tu41: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://run.plnkr.co' is therefore not allowed access.这是一个 CORS 问题。
标签: angularjs