AngularJS $ http.post [英] 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:
http://enable-cors.org/server_nginx.html
阅读评论 - 他们是真正信息
Read the comments--they are really informative.
另外:请参见preflighted请求在这里: https://开头developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
Also: see "Preflighted Requests" here: https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
这篇关于AngularJS $ http.post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!