I am using $.ajax call for download excel from .aspx page. But ajax throwing an error after Response.End. This is the code I used. Control is processing till Response.End()
then alert(textStatus);
giving parser error.
MasterPage.Master
$.ajax({
type: "POST",
url: "../Users/DownloadExcel.aspx",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(msg) {
alert(msg);
$.unblockUI();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
$.unblockUI();
}
});
DownloadExcel.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GenerateData()
End Sub
Private Sub GenerateData()
' Some Logic
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment; filename=" & filename)
Response.BinaryWrite(pck.GetAsByteArray())
Response.End()
End Sub