问题描述
这是我的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 响应状态码,表示请求方法为服务器所知,但目标资源不支持。