2011-08-19 6 views
3

Je fais une fonction dans la page Aspx et appelle cette fonction du script java, maintenant je veux télécharger des fichiers via le script Java. Mais Télécharger Dialog ne se ouvre pas .....Comment ouvrir la boîte de dialogue Téléchargement en 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:

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

} 

Répondre

6

Vous ne voulez pas faire un appel AJAX pour cela - il suffit de rediriger le navigateur:

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

Très très nxs .... –

Questions connexes