Send a jquery variable via ajax to PHP

1

I'm trying to send data from a table via Ajax to PHP. I'm doing this by transforming the table into JSON and thus sending via Ajax to PHP. The scritp looks like this:

<script type="text/javascript">
    $('#converter-tabela').click( function(){
        //alert("chegou!");    
        var table = $('#tabela').tableToJSON();
        console.log(table);
        alert(JSON.stringify(table)); 
        // Você envia os dados para o PHP utilizando AJAX
        $.ajax({
            // Enviamos os dados da tabela para um script PHP
            url: 'teste.php'
            , data: { 'dados_tabela': table }
            , method: 'POST'
        }).then(function(result) {
        // No retorno, apenas confirmamos
            if (result.success) {
                alert('Enviado para o servidor com sucesso!');
            }
        }).fail(function(result) {
            console.log(result);
        });
    });

And in PHP I'm just asking to show on the screen if everything went well:

<?php

ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

var_dump($_POST['dados_tabela']);
 print_r($_POST['dados_tabela']);?>

Only in the script it only reaches alert(JSON.stringify(table)); . The Ajax request does not seem to be working. I am using these links to the script: Ajax

and JSON

    
asked by anonymous 04.07.2018 / 17:29

0 answers