0

I've tried various ways to add to my serialized array, but I keep running into the following issues:

My first attempt results in: [object Object]&username=1 being sent.

var vals = {};

$.each($('#my-form').serializeArray(), function(i, field) {
  vals[field.name] = field.value;
});

$.ajax({
  url: "https://example.com",
  type: "POST",
  data: vals + "&username=1",
  complete: function(){
    alert("Success")
  }
});

My second attempt results in: Uncaught (in promise) TypeError: vals.push is not a function

var vals = {};

$.each($('#my-form').serializeArray(), function(i, field) {
   vals[field.name] = field.value;
 });

vals.push({name: 'username', value: 1});

$.ajax({
  url: "https://example.com",
  type: "POST",
  data: vals,
  complete: function(){
    alert("Success")
  }
});

Any ideas on what I'm doing wrong here?

Dodinas
  • 6,705
  • 22
  • 76
  • 108

0 Answers0