Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
为什么在这个AngularJS代码中HTTP POST返回为空?_Angularjs - Fatal编程技术网

为什么在这个AngularJS代码中HTTP POST返回为空?

为什么在这个AngularJS代码中HTTP POST返回为空?,angularjs,Angularjs,我正在使用下面的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,

我正在使用下面的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;
       });
我的代码是如何编写的,我是否遗漏了什么?是什么原因导致邮件为空


这不是与CORS相关的问题,因此也不是重复问题。

不太确定处理POST请求的服务是用哪种语言编写的,但在某些语言(例如PHP)中,您应该使用不同的编码来避免问题:

$http.post(url,  $.param(item), {headers: {'Content-Type':'application/x-www-form-urlencoded'} })

$.param将把对象转换为URL参数格式的键/值对

哪个主体是空的…请求还是响应?angular的哪个版本?除非我误解了它没有请求/响应,否则它不是API,而是webhook。webhook收到的帖子为空。HTTP 200被成功返回,webhook确实收到了帖子,它只是有一个空的正文。看来你误解了
$http
发出ajax请求,在请求正文中发送数据并等待响应。如果响应主体为空,则为api问题检查开发人员控制台是否存在错误<代码>加载失败https://requestb.in/18z1tu41: 对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许来源”标头。起源'https://run.plnkr.co因此,不允许访问。这是CORS问题。