我有以下代码:
$http({
url: config.apiUrl + 'mail/Sendmail',
method: 'POST',
data: JSON.stringify({
Body: $scope.Message,
Email: $scope.Email,
Name: $scope.Name
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
返回
{"Body":"test","Email":"test","Name":"test"}:""
这似乎不起作用,因为:""最后,否则它看起来就像我工作的邮差。
当我将数据代码更改为:
时data: $.param({
Body: $scope.Message,
Email: $scope.Email,
Name: $scope.Name
}),
我在参数下获取表单数据,我不再在网络选项卡中看到JSON,但它可以很好地对抗:
public bool SendEmail(EmailRequest email)
为什么JSON.Stringify会将:""
追加到我的电话中?
答案 0 :(得分:0)
在此demo fiddle中尝试使用 options: {
legend: { // remove the rectangle box from the legend
labels: {
boxWidth: 0,
}
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
display: true, // hides y axis labels
//min: 25, // at 25 or half way to say Half
//max: 50, // at 50 to say Full
//stepSize: 1,
}
}]
},
layout: {
padding: {
// Any unspecified dimensions are assumed to be 0
left: 50,
bottom: 10
}
},
}
。 'Content-Type': 'application/json'
工作正常,内容类型很重要。
JSON.stringify()
如果您仍希望将其作为var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($scope, $http) {
$scope.output = JSON.stringify({
Body: 'some',
Email: 'email@email.com',
Name: 'name'
});
$http({
url: 'https://jsonplaceholder.typicode.com/posts',
method: 'POST',
data: $scope.output,
headers: {
'Content-Type': 'application/json'
}
})
});
发送,请尝试此runnable fiddle。您需要将数据转换为URL编码字符串:
application/x-www-form-urlencoded; charset=UTF-