【问题标题】:Ajaxupload.js how to pass query param to ashx file asp.netAjaxupload.js 如何将查询参数传递给 ashx 文件 asp.net
【发布时间】:2013-10-16 23:17:31
【问题描述】:

您好,我多年来一直试图将参数传递给我的 ashx 页面

提前谢谢你

我目前正在使用此设置

upload

它使用

jQuery 有一个来自 Andris Valums 的插件 http://valums.com/ajax-upload/

代码示例

<script type="text/javascript">
$(function () {
        var customerID = getURLParameter("id");   
        new AjaxUpload('#UploadButton', {
            action: 'UploadHandler.ashx',
            data: { "customerID":"44455" },
            onComplete: function (file, response) {


                $('#UploadStatus').html("<div class=success>file has been uploaded sucessfully</div>");
                $("#UploadButton").hide();
            },
            onSubmit: function (file, ext) {
                if (!(ext && /^(jpg|png)$/i.test(ext))) {
                    alert('Invalid File Format.');
                    return false;
                }
                //$('#UploadStatus').html("Uploading...");              
            }
        });

    });
</script>

html端

<input type="button" id="UploadButton" class="btnReg charcoal" value="Upload Image" />

ashx 侧面

public void ProcessRequest(HttpContext context)
    {
        folderPath = HttpContext.Current.Server.MapPath("DownloadedFiles");
        customerID = context.Request.QueryString["customerID"];

        //Uploaded File Deletion
        if (context.Request.QueryString.Count > 0)
        {
            string filePath = folderPath + "//" + context.Request.QueryString[0].ToString();
            deleteIMG(filePath, context.Request.QueryString[0].ToString());
        }
        //File Upload
        else
        {
            //check if directory exist if not create one
            var ext = Path.GetExtension(context.Request.Files[0].FileName);
            var fileName = Path.GetFileName(context.Request.Files[0].FileName);

            if (context.Request.Files[0].FileName.LastIndexOf("\\") != -1)
            {
                fileName = context.Request.Files[0].FileName.Remove(0, context.Request.Files[0].FileName.LastIndexOf("\\")).ToLower();
            }

            fileName = GetUniqueFileName(fileName, HttpContext.Current.Server.MapPath("DownloadedFiles/"), ext).ToLower();

            string location = HttpContext.Current.Server.MapPath("DownloadedFiles/") + fileName + ext;
            context.Request.Files[0].SaveAs(location);            

            context.Response.Write(fileName + ext);
            context.Response.End();            
        }

    }

【问题讨论】:

    标签: javascript jquery asp.net ashx


    【解决方案1】:

    自从我使用它已经有一段时间了,但我认为它会执行 POST 并且能够在您的处理程序中读取这些参数,您需要从

    中读取它们
    context.Request.Params["paramname"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-23
      • 2017-03-08
      • 2017-05-28
      • 2018-09-30
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多