简体   繁体   English

jQuery ajax fileupload在IE9标准中不起作用?

[英]Jquery ajax fileupload is not working in IE9 standard?

Fileupload working everywhere like chrome, IE10, etc. But when My QA tested in IE9 it fails. Fileupload可以在chrome,IE10等任何地方正常工作。但是,当我的QA在IE9中进行测试时,它会失败。 Action controller get Request.Files are coming '0' length files. 动作控制器获取Request.Files即将为'0'长度的文件。

Is something wrong with IE9 or my code is wrong? IE9是否有问题或我的代码有问题?

function initSimpleFileUpload() {
            console.log("initSimpleFileUpload");              
            $('#fileupload').fileupload({
                url: '../admin/image/uploadfiles',
                dataType: 'json',
                acceptFileTypes: /^image\/(gif|jpeg|png|svg\+xml)$/,
                add: function(e, data) {
                    jqXHRData = data;
                },
                done: function(event, data) {

                },
                success: function(data, status, xhr) {
                    // console.log(data);
                    // console.log(data.url);
                    if (data.message == "false") {
                        //alert("filename already exists");
                        $("#oops_dialog").html("@Html.Raw(i18n_Models_Image.ImageFileExists)");
                        $("#oops_dialog").dialog("open");
                    }
                    else if (data.message == 'checksumExists') {
                        $("#oops_dialog").html("@Html.Raw(i18n_Models_Image.ImageCheckSumSame)");
                        $("#oops_dialog").dialog("open");
                    }
                    else if (data.message == 'fileTagNotExists') {
                        $("#oops_dialog").html("@Html.Raw(i18n_Models_Image.ImageTagTextBox)");
                        $("#oops_dialog").dialog("open");
                    }
                    else if (data.message == 'unexpectedError') {
                        $("#oops_dialog").html("@Html.Raw(i18n_Models_Image.ImageUploadUnexpectedError)");
                        $("#oops_dialog").dialog("open");
                    }
                    else if (data.message == 'fileTagSame') {
                        $("#oops_dialog").html("@Html.Raw(i18n_Models_Image.ImageSameFileTagNotAllowed)");
                        $("#oops_dialog").dialog("open");
                    }
                    else if (data.message == "success") {
                        window.location = data.url;
                    }
                },
                fail: function(event, data) {
                    if (data.files[0].error) {
                        alert('@i18n_Models_Image.UploadCancelled');
                    }
                }
            }).on('fileuploadprogressall', function(e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('.progress .progress-bar').css('width', progress + '%');
            });
        }


$('#fileupload').on('change', function(e) {
                if ($('#fileupload').length > 0) {
                    $('#lnkUploadSubmit').attr('disabled', false);
                    $('#divFileName').show();
                    $('.progress').show();
                } else {
                    $('#lnkUploadSubmit').attr('disabled', true);
                    $('#divFileName').hide();
                    $('.progress').hide();
                };
            });
            $('#fileupload').on('click', function(e) {
                console.log("click");
                $('#lnkUploadSubmit').attr('disabled', true);
                $('#divFileName').hide();
                $('#inputFileName').val('');

            });

controller 控制者

 [HttpPost]
    [Route("Admin/Image/UploadFiles")]
    public ActionResult UploadFiles()
    {
        try
        {
            var files = Request.Files;
            //checking file types and file max size
            var errMsg = CheckFileTypesAndMaxSize(files);
            if (errMsg != "success")
            {
                Error(errMsg);
                return Json(new { message = "error", url = Url.Action("Index", "Image") }, JsonRequestBehavior.AllowGet);
            }

Yes I guess something is wrong with IE 9. You need to submit the form to upload the file to server. 是的,我想IE 9出了点问题。您需要提交表格以将文件上传到服务器。 You can have a method in controller which will be called on page submit and this method will have a parameter something like this... HttpPostedFileBase file 您可以在控制器中有一个方法,该方法将在页面提交时被调用,并且该方法将具有类似如下的参数... HttpPostedFileBase文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM