AngularJS $ http.post

编程入门 行业动态 更新时间:2024-10-11 09:24:44
本文介绍了AngularJS $ http.post的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图做一个$ http.post并得到回应,我尝试在几个方面,但我无法得到它的工作。我发送数据(用户数据)是一个JSON对象。

I am trying to do an $http.post and get the response, I tried in several ways but I can't get it working. The data I am sending (userData) is an json object.

$http.post(url, userData) .success(function(data, status, headers, config) { console.log('post success'); console.log('data'); console.log(data); console.log('status'); console.log(status); console.log('headers'); console.log(headers); console.log('config'); console.log(config); }).error(function(data, status, headers, config) { console.log('post error'); console.log('data'); console.log(data); console.log('status'); console.log(status); console.log('headers'); console.log(headers); console.log('config'); console.log(config); });

和我的状态得到一个404。

And I am getting a 404 in status.

感谢您

推荐答案

响应是由于您的浏览器操作的方式从角$一个preflightOPTIONS方法请求不允许405方法HTTP和你的服务器没有按'科技支撑它。有一堆prerequisite反应,使CORS。如果你有机会到服务器,您可以添加对它的支持。一种选择是,作为前端代理使用nginx有这种配置的:

The "405 Method not allowed" response is because your browser is doing a "preflight" OPTIONS method request via angular $http and your server doesn't support it. There are a bunch of prerequisite responses to enable CORS. If you have access to the server, you can add support for it. One option is to use nginx as a front-end proxy with this kind of configuration:

enable-cors/server_nginx.html

阅读评论 - 他们是真正信息

Read the comments--they are really informative.

另外:请参见preflighted请求在这里: https://开头developer.mozilla/en-US/docs/HTTP/Access_control_CORS

Also: see "Preflighted Requests" here: developer.mozilla/en-US/docs/HTTP/Access_control_CORS

更多推荐

AngularJS $ http.post

本文发布于:2023-10-10 09:42:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AngularJS   http   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!