PHP and AJAX, what am I doing wrong? [closed]

-2

Friends, I'm doing an AJAX with PHP but the registry is going empty. What am I doing wrong?

function newColor() {
    var nome = document.getElementById("descricao_cor").value;
    var cor = document.getElementById("hexadecimal").value;
    alert (nome);
    alert(cor);
    $.ajax({
        url: "atualiza-cor.php",  
        type: "GET",
        data: { descricao_cor: "nome", hexadecimal: "cor" },   
        cache: false,
        success: function() { 
        document.adm.submit();
        $('#btnSelecionar').trigger('click');
    }
});
}

The alerts work fine. And then PHP looks like this:

//NOVA COR
if (isset($_GET['novaCor']) && ($_GET['novaCor']) != '') {
    echo $sql_novacor = 'INSERT INTO veiculos0_cores (descricao_cor,relevancia,hexadecimal) VALUES("' . $_POST['nome'] . '","", "' . $_POST['cor'] . '")';
    mysql_query($sql_novacor) or die(mysql_error());
}

And a record is inserted, but it is empty. I'm not finding the problem. Someone help me, please?

[]'s

    
asked by anonymous 14.06.2016 / 02:51

1 answer

1

You do not seem to be using the POST method. Simplify using $.post :

$.post({
    'url': "atualiza-cor.php",
    'data': {
        'descricao_cor': $("#descricao_cor").val(),
        'hexadecimal': $("#hexadecimal").val()
    },
    'success': function() { 
        document.adm.submit();
        $('#btnSelecionar').trigger('click');
    }
});

Remembering: You were returning a string for descricao_cor and hexadecimal . If you take the quotation marks it will return the value that is in the variables descricao_cor and hexadecimal .

    
14.06.2016 / 03:01