2017-05-05 63 views
-5

我使用AJAX2這裏沒有足夠的論據XMLHttpRequest.open

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest?redirectlocale=en-US&redirectslug=DOM/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress

描述監控Ajax請求的進步,但我收到以下錯誤「類型錯誤:沒有足夠的論據來XMLHttpRequest.open。 「

任何人都可以幫助爲什麼這個錯誤發生?

我的代碼是:

   var oReq = new XMLHttpRequest(); 
       oReq.addEventListener("progress", updateProgress); 
       oReq.addEventListener("load", transferComplete); 
       oReq.addEventListener("error", transferFailed); 
       oReq.addEventListener("abort", transferCanceled); 

       oReq.open(); 

       // ... 

       // progress on transfers from the server to the client (downloads) 
       function updateProgress (oEvent) { 
        if (oEvent.lengthComputable) { 
        var percentComplete = oEvent.loaded/oEvent.total; 
        console.log(percentComplete+ " percent completed."); 
        // ... 
        } else { 
         console.log(" Unable to compute progress information since the total size is unknown."); 
        // Unable to compute progress information since the total size is unknown 
        } 
       } 

       function transferComplete(evt) { 
        console.log("The transfer is complete."); 
       } 

       function transferFailed(evt) { 
        console.log("An error occurred while transferring the file."); 
       } 

       function transferCanceled(evt) { 
        console.log("The transfer has been canceled by the user."); 
       } 

實際工作中的錯誤是在這條線

oReq.open(); 
+0

哪裏是代碼? – binariedMe

回答

1

open()方法有三個參數 開放( '得到',網址,真或假或空)

1

的代碼示例在該文件中存在的不徹底,工作代碼。它旨在向您展示如何將進度跟蹤添加到現有的正在運行的XMLHttpRequest代碼中。

您需要自己填寫空白(或者更好:構建基本的基於XHR的腳本,然後添加進度跟蹤)。這包括替換:

oReq.open(); 

open的真實呼叫。見the documentation for open。至少你需要提供一個HTTP方法和一個URL(兩個字符串參數)。

相關問題