jquery reads data from a page table to generate bulk insert code and pass it to the background in AJAX mode

Source: Internet
Author: User
Tags bulk insert

The format of the table is more general, the first behavior field, the following behavior data, the table ID is detaillist.

$ ("#submitExcel"). Click (function () {    //Bind order Click event insertstr= "INSERT into funddetail values";//Insert string initial value $ ("# Detaillist tr:gt (0) "). each (function (i) {  //Gets the table all rows except the first row and adds a method to each row insertstr+=" (null, ";  Continue to increase the insert string $ (this). Find (' TD '). each (function (j) {///gets all the columns contained in the current row and adds a method to each column (that is, each cell), I is the ordinal number on the column if (j==7)// Because the 7th column in each row is a form control, the value {insertstr+=$ (this) is obtained in a different way. Find (' select '). val () + ",";  Continue to increase the insert string}else{insertstr+= "'" +$ (This). Text () + "',"//continue to increment the insert string, note the last comma}) insertstr= Insertstr.substring (0,insertstr.length-1); Delete each line last comma insertstr+= "),"; Sets the end of the INSERT statement for the current line, plus a comma to facilitate the next row of data}) insertstr=insertstr.substring (0,insertstr.length-1); Delete the last comma of the final insert string//The resulting insert string is passed to the background page for processing $.ajax ({type: "Post", Data:{insertstring:insertstr}, in Ajax mode). DataType: ' html ', url: ' phpcode/saveexcel.php ', success:function (data) {alert (data);});});

JQuery reads the data from the page table to generate bulk insert code and pass it to the background in AJAX mode

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.