1

我正在使用 jquery 插件来上传内容。但是当我上传内容时出现错误,显示输入意外结束。这是代码片段

  function uploadPacket(packet){

    var xhr = new XMLHttpRequest();
    var url = self.url + "?fileid="+self.fileDetails.fileId+"&token="+self.fileDetails.token+"&packet="+self.fileDetails.currentPackage;
    //alert(url);
    var fileDetails = self.fileDetails;
    updateProgress(fileDetails,0);
    xhr.open('POST', url, true);
    xhr.onprogress = function(e){
        updateProgress(fileDetails,e.position);

    // var percentComplete = (e.position / e.totalSize)*100;
    //console.log(percentComplete);
    //   progressBar.value = percentComplete;
    //  loadedSize.innerHTML = e.position;
    // speed.innerHTML = ((e.position-startedBytes)/1024)/((new Date().getTime()-timer)/1000)+ " kbps";

    };

    /**
     * If the server uploaded the packet successfully, then go to updateDetails() where log the success,
     * and initiate uploading the next package (if we not paused while it uploaded)
     */
    xhr.onload = function (e){
        //alert(e);
        var response = JSON.parse(xhr.responseText);  // here is the error showing

        if (response.action=="new_packet" && response.result=="success"){                
            updateDetails(fileDetails);
        }      

    }; 


    xhr.send(packet);
}  

请任何人帮助我

4

0 回答 0