Microsoft 边缘:SCRIPT0:SCRIPT0:未定义'FormData'



我在javascript中有一个XMLHttpRequest,它将FormData对象发布到服务器。此调用在 Chrome 中运行良好。在Microsoft Edge上,我看到此错误:"SCRIPT0:SCRIPT0:未定义'FormData'"。

这是我的片段:

function saveRecording(recordingData, endpoint, token) {
var randomNumber = Math.floor(100000 + Math.random() * 900000);
randomNumber = randomNumber.toString().slice(0, 4);
var recordingName = "Recording " + randomNumber;
var sender = {
sliceNumber: 1,
sliceMaxSize: 1024 * 1024,
sliceStart: 0,
sliceEnd: 1024 * 1024,
total: recordingData.blob.size,
recordlength: recordingData.length.toFixed(2),
fileName: '',
sendSlice: function () {
if (this.total > 0) {
var slice = undefined;
if (this.total >= this.sliceMaxSize) {
this.sliceEnd = this.sliceStart + this.sliceMaxSize;
}
else {
this.sliceEnd = this.sliceStart + this.total;
}
slice = recordingData.blob.slice(this.sliceStart, this.sliceEnd);
var isLastSlice = !((this.total - this.sliceMaxSize) > 0);
console.log(slice);
var formData = new FormData();
formData.append("data", slice);
formData.append("sliceMaxSize", this.sliceMaxSize);
formData.append("sliceNumber", this.sliceNumber);
formData.append("fileName", this.fileName);
formData.append("dictation", JSON.stringify(recordingData.dictation));
formData.append("isLastSlice", isLastSlice);
formData.append("length", this.recordlength);
formData.append("encoding", recordingData.encoding);
formData.append("name", recordingName);
//var params = 'data=ipsum&sliceMaxSize=binny&sliceMaxSize=binny&sliceMaxSize=binny&sliceMaxSize=binny&sliceMaxSize=binny&sliceMaxSize=binny';
var sender_this = this;
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
//readyState=4 means request finished and response is ready
if (this.readyState == 4) {
if (this.status == 200) {
//Success 
sender_this.fileName = JSON.parse(this.response).fileName;
sender_this.sliceNumber++;
sender_this.sliceStart = sender_this.sliceStart + sender_this.sliceMaxSize;
sender_this.total = sender_this.total - sender_this.sliceMaxSize;
// send the next slice
sender_this.sendSlice();
}
else {
//Fail
self.postMessage({ command: "saveRecordingFail", message: JSON.parse(this.response) });
}
}
};
request.open("POST", endpoint, true);
request.setRequestHeader("Accept", "application/json, text/plain, */*");
//request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.setRequestHeader(token.name, token.value);
request.send(formData);
}
else {
//recording completely sent to server, post message to worker caller
self.postMessage({ command: "saveRecordingSuccess" });
}
}
};
// send the slice
sender.sendSlice();
}

已尝试的解决方法:

我已经通过在成功创建 FormData 对象的边缘控制台上手动尝试来检查 FormData 是否在边缘中工作。

表单数据在边缘浏览器的控制台中工作正常

我尝试使用下面的示例代码进行测试,发现它在 MS Edge 浏览器(用户代理字符串:IE 11(上工作正常

<!doctype html>
<script>
let formData = new FormData();
formData.append('key1', 'value1');
formData.append('key2', 'value2');
// List key/value pairs
for(let [name, value] of formData) {
alert(`${name} = ${value}`);  
}
</script>
</html>

我建议您检查您尝试附加的所有值,并验证所有值是否具有正确且正确的值。

我建议您逐个检查所有值以找到有问题的值。

这可能有助于缩小问题范围。比你更容易解决问题。

参考:

表单数据

最新更新