【问题标题】:Problem with file upload using jquery on ie and chrome在 ie 和 chrome 上使用 jquery 上传文件的问题
【发布时间】:2011-08-09 21:30:44
【问题描述】:

我有这个简单的脚本

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Button ID="btnUploadFile" runat="server" Text="Button" />
    <input id="File1" type="file" />
</asp:Content>

$(document).ready(function ()
{
    $('#file_upload').fileUpload({
        url: 'UploadHandler.ashx',
        method: 'POST'
        // autoUpload: false,
//        onLoadAll: function (list)
//        {
//            __doPostBack('MainContent_UpdatePanel1', '');
//        },

    });

    $('#File1').css({ 'position': 'absolute', 'z-index': '-100' }); //hack for chrome, in fx enough is jquery hide()

    $('#MainContent_btnUploadFile').click(function ()
    {
        $('#File1').click();
        return false;
    });
});

和 http 处理程序

 public class UploadHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            HttpPostedFile uploadedfile = context.Request.Files[0];
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

当我启动此代码时,在 Firefox 中一切正常。在 http 处理程序中有我上传的文件。但是在 chrome 中我有例外,因为 Request.Files 没有文件。选择文件后在 Internet Explorer 中结束。它永远不会到达处理程序。为什么在不同的浏览器上会有那么多不同的结果? jquery上传插件位于这里http://aquantum-demo.appspot.com/file-upload 我能用它做什么?来自 asp.net 插件页面的示例在 chrome 上可以正常工作。我想我写的方式和这个例子一样,但是它不起作用。

【问题讨论】:

标签: jquery asp.net jquery-plugins upload


【解决方案1】:

根据我的经验,某些浏览器会将文件发送到context.Request.Files("&lt;filename&gt;").InputStream
其他人会使用context.Request.InputStream

我使用http://valums.com/ajax-upload/ 作为上传控件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    • 2012-08-30
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多