HTML源
<input id="UploadFile" type="file" name="UploadFile" />
<button type="button" onclick="UploadDocument();" class="RemoveButtonDefaultStyle">
Javascript功能
function UploadDocument() {
var fileInput = document.getElementById('UploadFile');
var xhr = new XMLHttpRequest();
xhr.open('POST', '/ControllerName/Action?id=14671');
xhr.setRequestHeader('Content-type', 'multipart/form-data');
//Appending file information in Http headers
xhr.setRequestHeader('X-File-Name', fileInput.files[0].name);
xhr.setRequestHeader('X-File-Type', fileInput.files[0].type);
xhr.setRequestHeader('X-File-Description', $("#UploadDescription").val());
//Sending file in XMLHttpRequest
xhr.send(fileInput.files[0]);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
$("#UploadFile").val('');
$("#UploadDescription").val('')
$("#UploadedFilesDiv").html(xhr.responseText);
}
}
return false; }
这在IE10,Chrome和Firefox中运行良好..但它对于IE 9或更低版本的浏览器都失败了。错误说“files [0]”未定义 我知道File是一个HTML5对象,在IE 9或更低版本的浏览器中不受支持。任何人都可以建议一下这可能是最简单的解决方法吗?