I am creating a UI. My back end code is in python. Python handlers are called by the javascript(using ajax). I am creating a csv file using python like below.
Results = []
filename = "D:/mydir/testing.csv"
csvfilename = "D:/mydir/testing.csv"
Results.append(["test1","test2","test3"])
with open(filename, 'wb') as f:
writer = csv.writer(f)
writer.writerows(Results)
csvfile = open(csvfilename, "r")
self.set_header("Content-Type", "application/csv")
self.set_header('Content-Disposition', 'attachment; filename="testing.csv"')
tempfile = csvfile.read()
self.write(tempfile)
Above code is creating file(with type 'Microsoft Office Excel Comma Separated Values File (.csv)').I am calling above handler on click using ajax call like below.
$.get("/filehandler", {startdate:startdate,enddate:enddate,reportname:reportname},function(data)
{
alert(data);
});
Actually my intention is on click over button it should ask for saving 'testing.csv' file. Now i have hard coded array contents, the data for the file should come from python. Is there any way to get solution using below code ?
<a onclick="function()" download>