Jquery Ajax request export Excel form implementation code _jquery

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.