Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
将Json数据从Angularjs发布到MVC控制器_Angularjs_Json_Asp.net Mvc 5 - Fatal编程技术网

将Json数据从Angularjs发布到MVC控制器

将Json数据从Angularjs发布到MVC控制器,angularjs,json,asp.net-mvc-5,Angularjs,Json,Asp.net Mvc 5,当我将JSON数据从AngularJS传递到MVC时。我正在犯错误 Http请求配置url必须是字符串或$sce受信任对象。收到:{“方法”:“POST”,“url”:“Home/SavePDDetails”,“数据类型”:“json”,“数据”:{“PD”:{“名称”:“qqq”,“地址”:“www”}}} MVC代码: AngularJS代码 在您的函数中尝试以下操作 使用JSON.stringify()包装JSON 如果数据和url作为config对象的属性传递,请不要使用$http.po

当我将JSON数据从AngularJS传递到MVC时。我正在犯错误

Http请求配置url必须是字符串或$sce受信任对象。收到:{“方法”:“POST”,“url”:“Home/SavePDDetails”,“数据类型”:“json”,“数据”:{“PD”:{“名称”:“qqq”,“地址”:“www”}}}

MVC代码: AngularJS代码
在您的函数中尝试以下操作

使用JSON.stringify()包装JSON


如果数据和url作为
config
对象的属性传递,请不要使用
$http.post
方法。只需使用
$http

  ̶$̶h̶t̶t̶p̶.̶p̶o̶s̶t̶(̶{̶
  $http({
    method: 'POST',
    url: 'Home/SavePDDetails',
    ̶d̶a̶t̶a̶t̶y̶p̶e̶:̶ ̶"̶j̶s̶o̶n̶"̶,̶
    data: {
      PD: $scope.PD
    }
  })

无需对数据进行字符串化,因为会自动执行该操作。

您可以控制台$scope.PD对象并添加问题吗?
.success
方法已被禁用。请参阅。
$scope.Click = function() {
  console.log('clicked');

  $http.post({
    method: 'POST',
    url: 'Home/SavePDDetails',
    datatype: "json",
    data: {
      PD: $scope.PD
    }
  }).success(function(response) {
      console.log('success');
      console.log(response);
  }).error(function(response) {
      console.log('error');
      console.log(response);
  });
}
var parameter = JSON.stringify({PD: $scope.PD});

$http.post('Home/SavePDDetails', parameter).
success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available
    console.log(data);
}).
error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});
  ̶$̶h̶t̶t̶p̶.̶p̶o̶s̶t̶(̶{̶
  $http({
    method: 'POST',
    url: 'Home/SavePDDetails',
    ̶d̶a̶t̶a̶t̶y̶p̶e̶:̶ ̶"̶j̶s̶o̶n̶"̶,̶
    data: {
      PD: $scope.PD
    }
  })