2014-09-20 54 views
0

嗨即时通讯开发一个Web应用程序,其中包含选项文件upload.im使用jquery和通用处理程序做这件事。上传文件asyn使用jquery

这里是我的代码:

<script type = "text/javascript"> 
     $(window).load(
      function() { 
      $("#<%=FileUploadcom.ClientID %>").fileUpload ({ 
       'uploader' : 'scripts/uploader.swf', 
       'cancelImg' : 'images/cancel.png', 
       'buttonText' : 'Browse Files', 
       'script' : 'Upload.ashx', 
       'folder': 'uploads', 
       'fileDesc' : 'Image Files', 
       'fileExt' : '*.jpg;*.jpeg;*.gif;*.png', 
       'multi' : true, 
       'auto': true 
      }); 
      } 
     ); 
    </script> 

<div> 
      <asp:FileUpload ID="FileUploadcom" runat="server" /> 
     </div> 

在不久的每一行:预计我得到错误的';'。如果我将其替换为:在执行时获取错误为XML分析错误:找不到元素。 任何人都可以帮助我使上述脚本完美工作。

我一般的处理程序代码:

<%@ WebHandler Language="C#" Class="Upload" %> 

using System; 
using System.Web; 
using System.IO; 

public class Upload : IHttpHandler { 

    public void ProcessRequest (HttpContext context) { 
     context.Response.ContentType = "text/plain"; 
     context.Response.Expires = -1; 
     try 
     { 
      HttpPostedFile postedFile = context.Request.Files["Filedata"]; 

      string savepath = ""; 
      string tempPath = ""; 
      tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPathN"]; 
      savepath = context.Server.MapPath(tempPath); 
      string filename = postedFile.FileName; 
      if (!Directory.Exists(savepath)) 
       Directory.CreateDirectory(savepath); 

      postedFile.SaveAs(savepath + @"\" + filename); 
      context.Response.Write(tempPath + "/" + filename); 
      context.Response.StatusCode = 200; 
     } 
     catch (Exception ex) 
     { 
      context.Response.Write("Error: " + ex.Message); 
     } 
    } 

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

如果我评论的scrit形式打开,如果我未收到意见如下 错误: enter image description here

在此先感谢。

+1

'$( “#<%= FileUploadcom.ClientID%>”)。文件上传({'开括号失踪 – 2014-09-20 11:49:10

+1

你的脚本有不正确的语法.'' $(窗口).load(函数(){ $ .fileUpload({})});'' – Hamix 2014-09-20 11:52:14

+0

感谢您的快速响应...缺少括号???让我检查 – Appdev 2014-09-20 11:54:25

回答

0

我可以问一个问题吗?如果您已经在使用文件上传控件,为什么还要使用自定义脚本?另外,你使用的是什么jQuery插件?如果你这样做是为了在上传中获得多个文件,FileUpload控件允许在4.5框架中输入多个文件。

+0

他使用插件上传文件时没有postback.Uploader with Progress酒吧也是。 – Hamix 2014-09-20 12:32:07

+0

作为哈米克斯说,我不想回发整个页面上文件上传以及我需要进度条,所以只有即时通讯使用jQuery。 – Appdev 2014-09-20 12:53:22

+0

我使用的插件是jquery-1.3.2.min.js 2. jquery.uploadify.js 3. uploader.fla 4. uploader.swf – Appdev 2014-09-20 12:54:41