gpt4 book ai didi

javascript - 发送 Angular POST 请求

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:12:51 25 4
gpt4 key购买 nike

我想通过 Angular 发送一个帖子请求。我的问题是 Angular 实际上发送一个获取请求而不是发布请求。我的 Angular 请求在这里:

$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 中看到了请求的参数。我该怎么办?

最佳答案

我会这样写:

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));
});

关于javascript - 发送 Angular POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41575059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com