Just post the code.
$ ("#btn-export"). Click (function () {
var exportexcel = "Export_excel";
Dataparams[exportexcel] = 1;
var params = $.param (dataparams);
var url = host+ "&" +params;
$ (' <form method= ' post ' action= ' + URL + ' ></form> '). Appendto (' body '). Submit (). remove ();
Delete Dataparams[exportexcel];
Briefly explain:
Use case: Ajax request server, return JSON data, the new requirement is to export the returned JSON to Excel table.
In the above code, Dataparams is an ajax request parameter, which is an object of type object defined earlier, because the request parameters are not fixed, so the request parameters are placed inside the object.
We know that Ajax request server, is not able to return to Excel table (this I am not sure, if the reader has a way to export, the invitation out of the way we learn), we need to convert the request to the page request, that is, to convert the form form to send the request, so that the data can be exported to The following code is also available:
$ (' <form method= ' post ' action= ' + URL + ' ></form> '). Appendto (' body '). Submit (). remove ();
To ensure that the page is clean and tidy, after the request is sent, the form form of the submission request is removed from the page.
Above this jquery Ajax request to export Excel form the implementation code is a small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.