2016-07-29 290 views
1

我有一個讓我瘋狂的問題,因爲我無法解決它。我想用我的應用程序上傳一些文件到服務器IIS。xmlhttprequest POST 405 - 不允許的方法

我的HTML代碼是:

<input id="files" type="file" /> 

而就在控制器時,我發現有一個新的文件被添加我使用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) 

enter image description here

在此先感謝!

回答

0

我有同樣的錯誤,問題是我試圖達到的方法不存在,所以我試圖使用POST,但在該URL的服務器上預計PUT。

查看服務器日誌可能會有所幫助!