I have a Jquery /HTML form which the user submits. I pass the form values to a url and based on the user form submission an Excel file is downloaded.
I populate the url with the form values and Excel files gets downloaded. example below:
http://localhost:8080/Service/getReport?report=pers_fees_report&startDate=20161201&endDate=20161231&programId=&balanceDate=&delivery=stream"
I was trying to use ajax but look like Ajax may not be necessary in this scenario.
Is their a way to send the user feedback when the excel file is downloaded or fails to download? is their any examples?
Get the form values
$("#submit").on('keypress click', function(e){
e.preventDefault();
reportName = $("#reportName").val();
start = $("#start").val();
end = $("#end").val();
sourceId = $("#sourceId").val();
programId = $("#programId").val();
sourceId2 = $("#sourceId2").val();
programId2 = $("#programId2").val();
balance = $("#balanceDate").val();
if(reportName !== '' ){
reportData ="report="+reportName+"&startDate="+start+"&endDate="+end+"&programId="+programId+"&balanceDate="+balance+"&delivery="+stream;
getExcel(newURL,reportData);
//Reset form
// $("form#reportName")[0].reset();
}
});
function getExcel
function getExcel(newURL,reportData) {
var Report = "http://localhost:8080/Service/getReport?report=pers_fees_report&startDate=20161201&endDate=20161231&programId=&balanceDate=&delivery=stream"
console.log("reportName " + reportName);
console.log("programId " + programId);
console.log("dbalanceDatet " + balanceDate);
console.log("sourceId " + sourceId);
$.ajax({
url: Report,
type: "post",
//data: {report:reportName,startDate:start,endDate:end,programId:programId},
//data: $('form#reportForm').serialize(),
success: function(data, textStatus, jqXHR) {},
error: function(jqXHR, textStatus, errorThrown) {
console.log('FAILED to get JSON from AJAX call' + jqXHR + textStatus + errorThrown);
}
});
}