【问题标题】:get the client side values inside ashx file获取 ashx 文件中的客户端值
【发布时间】:2013-10-02 12:01:33
【问题描述】:

我正在使用 uplodifiy 上传我的图片。这是我的代码如下。但是 在 Upload.ashx 处理程序中,我无法获取提交的值(Id 和 foo 值)。它们返回空值。 我该如何解决这个问题。谢谢。 我有这样的代码

  $(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();
..........
..........

【问题讨论】:

    标签: asp.net uploadify httphandler ashx


    【解决方案1】:

    formDataPost 方法一起使用

    如果方法选项设置为“get”,则额外数据可以作为查询字符串传递给脚本,如果设置为“post”,则可以通过标头传递。这一切都是在 formData 选项的帮助下完成的。根据您设置的方法选项(“post”或“get”),您可以在服务器端检索在 formData 选项中发送的信息。

    更多详情请参考Passing Extra Data

    【讨论】:

      猜你喜欢
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 2014-11-25
      • 2019-08-15
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多