Perform POST with Ajax

Asked

Viewed 55 times

0

I have a String that needs to be passed by parameter. However, the concatenated variable is interpreted as a new parameter and not a value. There is 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");
  • What HTML are you using? Maybe you can just do it $('form').serialize(); and he does it for you... explain the question better and you’ll get better answers.

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 using your $.ajax({}) so, maybe it works, I just put it in the order it will run and the string examples you put in.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.