Send more serialized form via AJAX?

0

I want to serialize my form, and send other variables. Is it possible?

Example:

var id = "1";

function register(){
  $.ajax({
    method: "post",
    url: "meu_script.php",
    data: $("#form").serialize(), //Aqui eu queria passar a variável *id*
  });
}
    
asked by anonymous 10.11.2017 / 01:33

1 answer

0

You can do this:

var ID = 100;
function register() {
    var data = $('#form').serializeArray();
    data.push({name: "id", value: ID});
    $.ajax({
        type: 'POST',
        url: 'meu_script.php',
        data: $.param(data),
    });
}

Using $ .param to serialize the form and add more values

    
10.11.2017 / 01:59