我遇到了一个让我发疯的问题,因为我无法解决它。我想用我的应用程序将一些文件上传到服务器 IIS。
我的 HTML 代码是:
<input id="files" type="file" />
当我检测到添加了新文件时,就在 Controller 中使用 XMLHttpRequest:
document.getElementById('files').addEventListener('change', function (e) {
var file = this.files[0];
var xhr = new XMLHttpRequest();
(xhr.upload || xhr).addEventListener('progress', function (e) {
var done = e.position || e.loaded
var total = e.totalSize || e.total;
console.log('xhr progress: ' + Math.round(done / total * 100) + '%');
});
xhr.open('POST', 'http://10.0.19.25:80/CG/files', true);
xhr.addEventListener('load', function (e) {
console.log('xhr upload complete', e, this.responseText);
});
xhr.send(file);
});
当我在 Chrome、Firefox 或 IE 上启动我的应用程序时,出现此错误:
POST http://10.0.19.25/CG/files 405 (Method Not Allowed)
提前致谢!
最佳答案
我遇到了同样的错误,问题是我尝试访问的方法不存在,所以我尝试使用 POST,但在服务器上,该 URL 应该是 PUT。
查看服务器日志可能会有帮助!
关于methods - xmlhttprequest POST 405 - 方法不允许,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38658291/