2013-10-02 68 views
0

我使用uplodifiy上傳圖片。這裏是我的代碼在below.but 裏面的Upload.ashx處理程序,我coulnt獲取提交的值(Id和foo值)。他們返回空值。 我該如何解決這個問題。謝謝。 我有這樣的代碼獲取ashx文件中的客戶端值

$(document).ready(function() { 

     var id = "55"; 
     var theString = "asdf"; 

     $("#<%=FileUpload1.ClientID%>").uploadify({ 
      'uploader': 'Upload.ashx', 
      'swf': 'uploadify/uploadify.swf', 
      'script': 'Upload.ashx', 
      'cancelImg': 'images/cancel.png', 
      'folder': 'upload', 
      'multi': true, 
      'buttonText': 'RESIM SEC', 
      'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg', 
      'auto': false, 
      'scriptData': { 'id': id, 'foo': theString} 
      ,onAllComplete: function (event, data) { 

      } 

     }); 
    }); 

和我的ashx文件是這樣的;

public void ProcessRequest(HttpContext context) 
    { 
     context.Response.ContentType = "text/plain"; 
     context.Response.Expires = -1; 
     try 
     { 

    //I tryed both way to get values both both return null values. 
      string pwd1 = context.Request["Id"]; 
      string pwd2 = context.Request.Form["Foo"]; 



      HttpPostedFile postedFile = context.Request.Files["Filedata"]; 
      string id = context.Request["id"]; 
      string savepath = ""; 
      string tempPath = ""; 

      tempPath = context.Request["folder"]; 

      //If you prefer to use web.config for folder path, uncomment below line: 
      //tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; 


      savepath = context.Server.MapPath(tempPath); 
      string filename = postedFile.FileName; 
      if (!Directory.Exists(savepath)) 
       Directory.CreateDirectory(savepath); 
      string ext = System.IO.Path.GetExtension(filename); 
      string resimGuid = Guid.NewGuid().ToString(); 
.......... 
.......... 

回答

1

使用FORMDATA郵政方法

額外的數據可以傳遞給腳本無論是作爲查詢字符串,如果該方法選項設置爲「GET」,或通過標題,如果它被設置發佈'。這一切都是在formData選項的幫助下完成的。根據您設置的方法選項('post'或'get'),您可以檢索服務器端formData選項中發送的信息。

欲瞭解更多detils請參閱Passing Extra Data

+0

完美,非常感謝你 – sakir