【问题标题】:jQuery form not working on internet explorerjQuery 表单无法在 Internet Explorer 上运行
【发布时间】:2013-03-05 02:49:23
【问题描述】:

我正在使用 jQuery 表单上传文件并将它们保存到数据库中,我的代码在 chrome 和 mozilla 中运行良好,但在 Internet Explorer 中无法开始上传;我是 grails 框架,我的代码如下:

<g:form controller="uploadImage" action="uploadImage" enctype="multipart/form-data" name="imageUploaderForm" id="imageUploaderForm">
    <input type="file" name="image" id="image" onchange="submitImageUploaderForm()" />
    <g:hiddenField name="imageType" value=""/>
</g:form>

$("#imageUploaderForm").ajaxForm({
    uploadProgress: function(event, position, total, percentComplete) {
        $("#progressbar").progressbar({
            value : percentComplete
        });
        $(".progress-label").html(percentComplete+" %");
    },
    complete: function(response){
        //something
    }
});

function submitImageUploaderForm(){
    //This method gets called !
    $("#imageUploaderForm").submit();
}

在控制器中我有以下内容

def uploadImage = {
    def response = [result:false,message:"Image could not be uploaded.",uploadInstanceId:0]
    def uploadImage = new UploadImage(params)
    if(uploadImage.save()) response = [result:true,message: "Image uploaded sucessfully.",uploadInstanceId:uploadImage.id]
    render response as JSON
}

当我尝试上传文件时,页面中没有任何反应,但过了一段时间后出现以下异常:

Message: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: Read timed out

【问题讨论】:

  • 您是否尝试使用 Ajax 上传文件?如果是这样,这将不起作用。研究主题。
  • 是的,我正在尝试使用 AJAX 上传文件。此代码在 mozilla 和 firefox 中运行良好,但在 Internet Explorer 中无法运行。

标签: jquery ajax internet-explorer grails file-upload


【解决方案1】:

遗憾的是,通过 Ajax 上传文件在 IE 中不起作用。请参阅有关文件上传的 jQuery 文档。 http://jquery.malsup.com/form/#file-upload

正如 James 所指出的,这个问题以前曾被问过,而且它并不是 Grails 特有的。 JQuery Ajax Form with File Upload not working in IE

【讨论】:

    【解决方案2】:

    我在 Internet Explorer 中使用隐藏 iFrame 上传文件,而在其他浏览器中,文件是使用上面显示的代码使用 AJAX 上传的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 2015-08-07
      • 2023-03-31
      • 2019-08-09
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      相关资源
      最近更新 更多