dwa4821 2016-06-30 07:00 采纳率: 71.4%
浏览 5301
已采纳

一般处理程序怎么接收ajaxsubmit data参数

接收不到

一个script文件 一个ashx 功能是下载文件

script文件

 $("#btnDownLoad").click(function () {
        $("#form1").ajaxSubmit({
            url: "Handler4.ashx",
            type: "post",
            data:{"title":"downLoad"},
            resetForm: "true",
            beforSubmit: function () {
            },
            success: function (msg) {
            },
            error: function (jqxhr, errorMsg, errorThrown) {
            }
        })

    })

ashx

  string title=context.Request.Form["title"];
            if (title == "downLoad")
            {
                string fileName = "downLoadFile.txt";
                string filePath = context.Server.MapPath("~/");

                FileInfo fileinfo = new FileInfo(filePath);

                if (fileinfo.Exists == true)
                {
                    const long size = 102400;
                    byte[] buffer = new byte[size];
                    context.Response.Clear();
                    FileStream fileStream = File.OpenRead(filePath);
                    long fileLength = fileStream.Length;

                    context.Response.ContentType = "application/octet-stream";
                    context.Response.AddHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(fileName));
                    //如果客户端连在服务器上
                    while (fileLength > 0 && context.Response.IsClientConnected)
                    {
                        int lengthRead = fileStream.Read(buffer, 0, Convert.ToInt32(size));
                        context.Response.OutputStream.Write(buffer,0,lengthRead);
                        context.Response.Flush();
                        fileLength = fileLength - lengthRead;

                    }
                    context.Response.Close();
                }


            }
  • 写回答

4条回答 默认 最新

  • Go 旅城通票 2016-06-30 07:21
    关注

    ajaxsubmit 是jquery.form.js这个插件的方法?如果是就和普通表单提交一样,附加的data用context.Request.Form["title"]获取

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮