Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var $TABLE = $('#table');
- var $BTN = $('#export-btn');
- var $EXPORT = $('#export');
- jQuery.fn.pop = [].pop;
- jQuery.fn.shift = [].shift;
- $BTN.click(function () {
- var $rows = $TABLE.find('tr:not(:hidden)');
- var headers = [];
- var datas = [];
- // Get the headers (add special header logic here)
- $($rows.shift()).find('th:not(:empty)').each(function () {
- headers.push($(this).text());
- });
- // Turn all existing rows into a loopable array
- $rows.each(function () {
- var $td = $(this).find('td');
- var h = {};
- // Use the headers from earlier to name our hash keys
- headers.forEach(function (header, i) {
- h[header.replace(/\n\s+/g, "")] = $td.eq(i).text().replace(/\n\s+/g, "");
- });
- datas.push(h);
- console.log(h);
- });
- // Output the result
- $EXPORT.text(JSON.stringify(datas));
- $.ajax({
- url:'/preview/',
- type:'POST',
- contentType: "application/json; charset=utf-8",
- data:{
- json_respons: datas,
- },
- dataType: 'json',
- success: function(datas){
- console.log(datas);
- },
- error: function(datas){
- alert(datas);
- },
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement