Javascript 发送一个有角度的POST请求
我想通过电子邮件发送一个post请求。我的问题是实际上发送get请求而不是post请求。我的要求如下:Javascript 发送一个有角度的POST请求,javascript,angularjs,post,request,Javascript,Angularjs,Post,Request,我想通过电子邮件发送一个post请求。我的问题是实际上发送get请求而不是post请求。我的要求如下: $http({ method: 'POST', url: pages_url, params: { 'page': $scope.current_page_id, 'news': JSON.stringify(news), 'method': 'POST' }
$http({
method: 'POST',
url: pages_url,
params: {
'page': $scope.current_page_id,
'news': JSON.stringify(news),
'method': 'POST'
}
}).then(function (response) {
alert(JSON.stringify(response));
});
当我使用浏览器的“网络”选项卡调试请求时,我会在服务器url中看到请求的参数。我该怎么办?试试这个:
function yourFunction(param1, param2) {
return $http({
method: 'POST',
url: yourUrl,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {username: param1, password: param2}
})
.then(function(response) {
return response;
});
}
我会这样写:
var req_body = {
page: $scope.current_page_id,
news: JSON.stringify(news),
method: 'POST' // <- is this really a parameter you want or do you misunderstood the post as a request?
};
$http.post(pages_url, req_body)
.then(function (response) {
alert(JSON.stringify(response));
});
var-req\u-body={
页码:$scope.current\u page\u id,
新闻:JSON.stringify(新闻),
方法:'POST'//你在网络选项卡中看到了什么?你能在这里发布吗?@suzo我看到了这个:服务器IP/报纸/编辑?方法=POST&news=[{“body”:“,”editor”:“,”editable1”,“title”:“,”},{“body”:“,”editor”:“editable2”,“title”:“}]&page=5872525f3c6130641da66e56