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
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
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>