2014-09-20 18 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