Perform POST with Ajax

0

I have a String that I need to pass by parameter. However the concatenated variable is interpreted as a new parameter and not a value. Is there a way to pass String by parameter with this character (&)?

Thank you in advance.

var codhtml = '&teste = 5';

$.ajax({
    type: 'post',
    url: 'salvarDados.php',
    data: 'codhtml=' + codhtml + '&motivoid=2' + '&formatoid=2' + '&motivonome=Nome',
    dataType: 'html',
    success: function(txt) {
        alert("Sucesso,");
    },
    error: function(result) {
        alert("Erro ao Salvar");
    
asked by anonymous 14.06.2016 / 22:32

1 answer

0

See if it works like this.

        var formatoid= '2';
        var motivoid = '2';
        var motivonome = 'Nome';
        var teste = '5';
$.ajax({

            url: 'salvarDados.php',
            data: {teste:teste, motivoid :motivoid, formatoid: formatoid ,motivonome : motivonome },
            method: 'POST',
            success : function(txt){
                 alert("Sucesso,");
            },
            error: function(result) {
                alert("Erro ao Salvar");

Try to use your $ .ajax ({}) so, maybe it works, I just put it in the order it will run and the string examples you put in.

    
14.06.2016 / 22:50