2014-06-08 71 views
0

嗨朋友我有一個窗體,其中有一些文本框,下拉式以及圖像。我正在使用js來保存表格細節。我正在使用uploadify插件將我的圖像上傳到本地文件夾。我實現了所有這些功能,但是直到現在我還是使用了一個aspx代碼。爲了上傳目的,我們必須選擇ashx。所以它會像兩個服務器端發佈一樣發生!使用uploadify與ashx處理程序

所以我想將我的數據保存在ashx頁面而不是aspx。

但是我很困惑在哪裏開始我的upload.please有人幫助我這個!

我正在保存我的值在像下面的保存按鈕事件!

 self.AddEvent = function (args) {   

     // Here--> $('#file_upload').uploadify('upload'); 

        ajax.Post("../Scripts/uploadify/UploadHandler.ashx", JSON.stringify({ objEnt: args }), false).success(function (data) { 

        if (data.d[0] > 0) { 
     // or Here-->   $('#file_upload').uploadify('upload'); 
        alert('success'); 
        } 

和我的文件上傳設定S1是:

$('#file_upload').uploadify({ 
       'swf': '../Scripts/uploadify/uploadify.swf', 
       'uploader': '../Scripts/uploadify/UploadHandler.ashx', 
       'method': 'post', 
       'formData': { 'someKey': Filename }, 
       'buttonText': 'Browse', 
       'auto': false, 
       'folder': 'upload', 

       'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png', 
       'onSelect': function (file) { 
        var ext = file.name.split('.').pop(); 
        $("#filename").val(Filename + '.' + ext); 
       }, 
       'onUploadSuccess': function (file, data, response) { 

        if (response == true) { 

         $("#eventGrid").jqxGrid('updatebounddata'); 



        } 

       } 

      }); 

這是不可能調用self.AddEvent在我的情況 'onUploadsuccess' ... !!! 請給我建議一些最好的方式來存儲我的數據和圖像在ashx處理程序中的同一時間。

ASHX:

public void ProcessRequest(HttpContext context) 
{ 

    context.Response.ContentType = "application/json"; 
    var data = context.Request; 
    var sr = new StreamReader(data.InputStream); 
    var stream = sr.ReadToEnd(); 
    var javaScriptSerializer = new JavaScriptSerializer(); 
    var asd = javaScriptSerializer.Deserialize<RootObject>(stream); 
    string Newname = context.Request.Form["someKey"]; 
    BAL Bl = new BAL(); 

    string[] args = new string[2]; 
    //AddEvent method will add my data into database add return response "Success"// 
    args = AddEvent(asd.objEnt); 

     HttpPostedFile PostedFile = context.Request.Files["Filedata"]; 

      string ext = Path.GetExtension(PostedFile.FileName); 
      string savepath = ""; 
      string temppath = ""; 
      temppath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; 
      savepath = context.Server.MapPath(temppath); 
      string fileName = Newname + ext; 
      if (!Directory.Exists(savepath)) 
       Directory.CreateDirectory(savepath); 

      PostedFile.SaveAs(savepath + @"\" + fileName); 

      context.Response.Write(temppath + "/" + fileName); 
      // context.Response.Write(args); 

      context.Response.StatusCode = 200; 

     } 
    } 
+0

你可以使用它像這樣,第一次加載所有圖像後,如果成功的情況發生,在uplodify成功裏面,使anaother AJAX調用,它具有保存數據 – sakir

+0

不過說我一件事我怎麼能得到ashx處理程序的響應返回的值?我知道context.response.write(args)會在控制檯中寫入。但是,我怎麼能得到Ajax成功返回的值? – user3640046

+0

在ashx中使用會話 – sakir

回答

0
$("#<%=FileUpload1.ClientID%>").uploadify({ 
      'uploader': 'Upload.ashx', 
      'swf': 'uploadify/uploadify.swf', 
      'script': 'Upload.ashx', 
      'cancelImg': 'images/cancel.png', 
      'folder': '../Upload', 
      'multi': true, 
      'buttonText': 'select picture', 
      'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg', 
      'auto': false, 
      'onUploadStart': function() { 


      } 
     }); 


$.ajax({ 
      type: "POST", 
      url: 'WebServiceAdmin.asmx/SaveData', 
      data: "{'p':'" + datam+ "'}", 
      dataType: "json", 
      contentType: "application/json; charset=utf-8", 
      success: function (d) { $('#FileUpload1').uploadify('upload', '*'); }, 
      error: function() { } 
     }); 
+0

與此ashx將被稱爲兩次..?一個在發佈時,第二個是在上傳圖片時.. – user3640046

+0

關於Ajax的成功功能我怎麼能得到ashx在你的情況下是'd'的迴應.. ??在我的代碼中看到args!根據我的反應,我必須做其他事情 – user3640046

+0

U可以檢查uplodify document.shoul是另一個evet哪個triger全部更新完成 – sakir