2014-06-08 75 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