2011-08-19 5 views
3

Aspx 페이지에서 함수를 만들고이 함수를 Java 스크립트에서 호출합니다. 이제 Java 스크립트를 통해 파일을 다운로드하려고합니다. 그러나 다운로드 대화 상자Javascript에서 다운로드 대화 상자를 여는 방법은 무엇입니까?

..... 열리지 않습니다 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를 : 당신이 AJAX 호출을하지 않으

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."); 
      } 
     });   

} 

답변

6

을 이를 위해 브라우저를 리디렉션하면됩니다.

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

Very Very Tha nxs .... –

관련 문제