我创建了一个示例(index.html
),当您单击该按钮时,该框的文本内容必须为“Hello World”,该文件位于include.html
文件中。问题出在send()
方法,在控制台中说明
POST http://localhost:8080/include.html 405(不允许的方法)
document.querySelector.onclick @ main.js:10
这是main.js
文件:
document.querySelector('button').onclick = function() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "include.html", true);
xhr.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
document.querySelector('div').innerHTML = this.responseText;
}
}
xhr.send();
}
有人可以帮助我并给我一些关于这个问题的提示吗?谢谢。
答案 0 :(得分:1)
405错误表示:The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.
尝试使用“GET”而不是“POST”