How to concatenate serialized data from a form to the javascript string? [closed]

-1

How can I concatenate a serialized data variable var dados = $(form).serialize(); with a second variable, for example var x ="2222" ?

Thank you for your attention! Horacio

    
asked by anonymous 22.11.2018 / 17:59

1 answer

1

Just get the result of the serialized variable and concatenate it with the existing one:

$(document).ready(function(){
    $("button").click(function(){
        var dados = $("form").serialize();
        var x = "2222";
        
        $("h1").text(dados+"&x="+x);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><formaction="">
  Nome: <input type="text" name="name" value="Fulano"><br>
  Idade: <input type="text" name="idade" value="34"><br>
</form>
<br>
<button>Serializar</button>

<h1></h1>
    
22.11.2018 / 18:12