林提交我的文件通过的jQuery在Firefox中使用Jform.js插件,它的工作,但是当我尝试在IE8文件中正确sumbitted但文件上传控件被隐藏起来,进一步当我发表评论IE条件,那么文件上传控制犯规获得隐藏但是当我检查Request.Files [0] .ContentLength在我的控制器它有0值。这是我的代码,什么可能是即时通讯做错了什么?即时通讯使用Asp.net MVC和jQuery-1.4.2

        var myform = document.createElement("form");    
        myform.style.display = "none"
        myform.action = "/Media/AjaxSubmit";
        myform.enctype = "multipart/form-data";
        myform.method = "post";
        var imageLoad;
        var imageLoadParent;
        if (document.all) {//IE
            imageLoad = document.getElementById(fileId);
            imageLoadParent = document.getElementById(fileId).parentNode;
            myform.appendChild(imageLoad);
            document.body.appendChild(myform);
        }
        else {//FF          
                imageLoad = document.getElementById(fileId).cloneNode(true);
                myform.appendChild(imageLoad);
                document.body.appendChild(myform);          
        }    
        $(myform).ajaxSubmit({ success: function (responseText) {    
});
有帮助吗?

解决方案 2

解决方法很简单我只是添加浏览控制时,它响应于来自ajaxSubmit会函数返回并代码如下

            $(myform).ajaxSubmit({ success: function (responseText) {
            if (document.all) {//IE
                imageLoadParent.appendChild(myform.firstChild);
            }
            else//FF                     
            {
                document.body.removeChild(myform);
            }

其他提示

什么是.ajaxSubmit前的谵妄?它看起来就像从90年代末的代码。我会建议您只需使用jQuery,而不用担心跨浏览器的问题:

$('form')
    .attr('action', '/Media/AjaxSubmit')
    .attr('method', 'post')
    .attr('enctype', 'multipart/form-data')
    .hide()
    .append($('#' + fileId).clone())
    .ajaxSubmit({
        success: function(responseText) {
            // ...
        }
    })
    .appendTo('body');

注:硬编码的形式动作看起来难看。你应该考虑使用HTML辅助生成URL。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top