开发者

How To Open Download Dialog box in Javascript?

开发者 https://www.devze.com 2023-03-29 01:06 出处:网络
I makefunction in Aspx pageand call this function from java script , Now i want to downloadfiles through Java script. But Download Dialog Doesn\'t Open.....

I make function in Aspx page and call this function from java script , Now i want to download files through Java script. But Download Dialog Doesn't Open.....

Download.Aspx:

            string pid = Request.QueryString["Did"].ToString();

            DataTable dt;
            dt = common.GetFilePath(Convert.ToInt64(pid));
            FilePath = dt.Rows[0]["FilePath"].ToString();
            FileName = dt.Rows[0]["FileName"].ToString();
            FilePath = System.Web.HttpContext.Current.Server.MapPath("~//" + FilePath +    "");

            Response.Clear();
            Response.ClearHeaders();
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=" + FileName + "");
            Response.WriteFile(FilePath);
            Response.End();

Jquery:

function DownloadAttach(pid){

   $.ajax({ type: "POST",
            url: "http://localhost:1988/DownLoad.aspx?Did=" + pid,
      开发者_运维知识库      dataType: "xml",

            processData: true,
            //error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest, textStatus, errorThrown); },
            success: function(xml) {

              //ShowMsg("projSaveMsg", "Attachment Deleted.");
            }
        });        

}


You don't want to make an AJAX call for this - just redirect the browser:

function DownloadAttach(pid){
     window.location = "http://localhost:1988/DownLoad.aspx?Did=" + pid;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消