我创建了一个示例 (index.html
),当您单击该按钮时,该框的文本内容必须是“Hello World”,该内容位于 include.html
文件。问题出在 send()
方法上,该方法在控制台中显示
POST http://localhost:8080/include.html 405 (Method Not Allowed)
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();
}
有人可以帮助我并给我一些关于这个问题的提示吗?谢谢。
最佳答案
405错误的意思是:Request-URI标识的资源不允许使用Request-Line中指定的方法。响应必须包含一个Allow header ,其中包含所请求资源的有效方法列表。
尝试使用“GET”而不是“POST”
关于javascript - AJAX 的发送方法有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39120709/