如何解决JSON post 请求显示 405 not allowed 错误使用 XMLHttpRequest()
这是我的js代码:
var myreq=new XMLHttpRequest();
myreq.open("GET","https://<username>.github.io/test/data/data.json",true);
myreq.onload =function(){
console.log(JSON.parse(myreq.response));
}
myreq.send();
const data={
"name": "jayant","job": "leader"
};
function here()
{
var myreq1=new XMLHttpRequest();
myreq1.onload = () => {
// print JSON response
if (myreq1.status >= 200 && myreq1.status < 300) {
// parse JSON
const response = JSON.parse(myreq1.responseText);
console.log(response);
}
};
myreq1.open("POST",'https://<username>.github.io/test/data/data.json');
myreq1.setRequestHeader('Content-Type','application/json');
myreq1.send(JSON.stringify(data));
}
[
{
"name1":"jayant","age":58,"pass":"LetsLearnjson"
},{
"name1":"jayant2","age":45,"pass":"ok"
},{
"name1":"jayant3","age":24,"pass":"test"
},{
"name1":"abcd","age":75,"pass":"abcd"
}
]
当我尝试发布时遇到此错误:
POST https://<username>.github.io/test/%22https://<username>.github.io/test/data/data.json%22 405
请帮忙。我已经尝试了很多在线可用的东西,但似乎没有任何效果
解决方法
当 Web 服务器配置为无法对特定 URL 执行特定操作时,会出现 405 Method Not Allowed 错误。它是一个 HTTP 响应状态码,表示请求方法为服务器所知,但目标资源不支持。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。