TypeError: $ (...) .tableToJSON is not a function

0

Greetings When I click the button in my project the following TypeError error is displayed: $ (...). TableToJSON is not a function, I am using the tableToJSON plugin

Code:

$('document').ready(function(){
    $('#TermVenda').click(function(){
        var table =$('#products-table').tableToJSON(); 
        console.log(table);
        document.write(JSON.stringify(table));
        alert(JSON.stringify(table));
    });           
 });             

HTML table: <!DOCTYPE html> <html> <head> <title>Pagina do Cliente</title> <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="js/jquery.tabletojson.min.js"></script> </head> <body> <table id="products-table" class="table table-hover table-bordered"> <thead> <tr> <th>Produto</th> <th>Preço </th> <th>Qtd</th> <th>Valor</th> <th>Ações</th> </tr> </thead> <tbody> <tr> <td>Banana</td> <td>20</td> <td>5</td> <td>100</td> <td>x</td> </tr> <tr> <td>Alho</td> <td>20</td> <td>5</td> <td>100</td> <td>x</td> </tr>
</tbody> </table> <button id="TermVenda">Converter</button> </body> </html>

    
asked by anonymous 11.01.2018 / 11:51

1 answer

1

You may not have included jquery or jquery.tabletojson.js on your page. Open your developer console by pressing F12 on your browser, and make sure there are no JS loading errors. I've set up a test page as per the link below and it works correctly.

TableToJson DEMO Page

    
11.01.2018 / 12:12