Javascript 发布网站后,使用AngularJS发布表单返回405代码
当我将表单中的数据发布到接收到的服务器时,我遇到了一个问题:Javascript 发布网站后,使用AngularJS发布表单返回405代码,javascript,angularjs,post,methods,http-status-code-405,Javascript,Angularjs,Post,Methods,Http Status Code 405,当我将表单中的数据发布到接收到的服务器时,我遇到了一个问题: angular.js:14642 Possibly unhandled rejection: {"data":"<html>\n<head><title>405 Not Allowed</title></head>\n<body bgcolor=\"white\">\n<center><h1>405 Not Allowed</h1&g
angular.js:14642 Possibly unhandled rejection: {"data":"<html>\n<head><title>405 Not Allowed</title></head>\n<body bgcolor=\"white\">\n<center><h1>405 Not Allowed</h1></center>\n</body>\n</html>","status":405,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"/messages","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"Method Not Allowed"}
任何帮助都将不胜感激
编辑:我添加了响应标题,但没有任何更改
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://www.stundji.info');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT,');
res.setHeader('Access-Control-Allow-Headers', 'application/json');
res.setHeader('Access-Control-Allow-Credentials', false);
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
问题解决了
问题来自GitHub页面。我换成了Heroku,一切都恢复了正常。我给每个人的建议是不要在GitHub页面上托管他们的网站,似乎它对某些请求有限制。问题已经解决 问题来自GitHub页面。我换成了Heroku,一切都恢复了正常。我给每个人的建议是,不要把他们的网站放在GitHub页面上,似乎它对某些请求有限制
$http({
method: 'POST',
url: '/messages',
headers: { "Content-Type": "application/json" },
data: app.contactData
})
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://www.stundji.info');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT,');
res.setHeader('Access-Control-Allow-Headers', 'application/json');
res.setHeader('Access-Control-Allow-Credentials', false);
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});