xhr.send无法执行

时间:2016-12-21 14:47:50

标签: javascript xmlhttprequest

当我将xhr对象(在POST模式下)放在循环中时,我遇到了问题。 在930次成功迭代后,我遇到以下错误:未捕获DOMException:无法执行'发送' on' XMLHttpRequest':无法加载。



 var compteur = 0;
        for(var i=0;i< (size) ; i++) {
            console.log("First");
            var xhr = new XMLHttpRequest();
            console.log(dirPath+obj[i]);
            xhr.open('GET', dirPath+obj[i],true);
            xhr.responseType = 'blob';
            xhr.onload = function(e) {
                if (this.readyState == 4 && (this.status == 200 || this.status == 0)) {
                    var blob = this.response;
                    console.log(blob);
                    var dataSet;
                    var reader = new FileReader();
                    reader.onload = function(blob) {
                        console.log("start");
                        console.log(compteur);
                        var arrayBuffer = reader.result;
                        var byteArray = new Uint8Array(arrayBuffer);
                        dataSet = dicomParser.parseDicom(byteArray);
                        var element = dataSet.elements['x00100010'];
                        var newValue = fileName;
                        for(var k=0; k < element.length; k++) {
                            var char = (newValue.length > k) ? newValue.charCodeAt(k) : 32;
                            dataSet.byteArray[element.dataOffset + k] = char;
                        }
                        var dicom = new Blob([dataSet.byteArray], {type: "application/dicom"});
                        var fd = new FormData();
                        fd.append("afile",dicom, obj[compteur]);
                        var xhrSave = new XMLHttpRequest();
                        xhrSave.open('POST', 'php/saveAnonymizedFile.php?chemin_destination='+cheminDestination, false);
                        xhrSave.onreadystatechange = function() {
                            if(xhrSave.readyState == 4) {
                                compteur++;
                                if(compteur == size){
                                     var xhrDeleteDir = new XMLHttpRequest();
                                     xhrDeleteDir.open('POST', 'php/deleteDestDir.php?chemin_destination='+cheminDestination+'&chemin_source='+cheminSource, true);
                                     xhrDeleteDir.send();
                                    console.log(" is Done 1");
                                }
                            }
                        };
                        xhrSave.send(fd);
                    };
                    reader.readAsArrayBuffer(blob);
                }
            };
            xhr.send();
        }
&#13;
&#13;
&#13;

0 个答案:

没有答案