Jquery reads data from the table on the page to generate batch insert code and sends it to the background in ajax mode.

Source: Internet
Author: User

Jquery reads data from the table on the page to generate batch insert code and sends it to the background in ajax mode.

The table format is more common. The first behavior field contains the following behavior data. The table id is detailList.

$ ("# SubmitExcel "). click (function () {// bind the insertStr = "insert into funddetail values"; // the initial value of the insert string $ ("# detailList tr: gt (0 )"). each (function (I) {// obtain all rows of the table except the first row, and add the insertStr + = "(null ,"; // continue adding the insert string $ (this ). find ('td '). each (function (j) {// obtain all columns contained in the current row, and add a method to each column (that is, each cell, I is the sequence number in the column if (j = 7) // Since each row is a Form Control in column 7th, use different methods to obtain the value {insertStr + = $ (this ). find ('select '). val () + ","; // continue adding the insert string} else {insertStr + = "'" + $ (this ). text () + "'," // Add the insert string. Note that there is a comma at the end.}) insertStr = insertStr. substring (0, insertStr. length-1); // Delete the last comma insertStr + = "),"; // set the end of the insert statement for the current row, with a comma, to facilitate the next row of Data}) insertStr = insertStr. substring (0, insertStr. length-1); // delete the comma at the end of the final insert string // use ajax to pass the preceding insert string to the background page for processing $. ajax ({type: "post", data: {insertstring: insertStr}, dataType: 'html ', url: "phpCode/saveExcel. php ", success: function (data) {alert (data );}});});

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.