I'm using $.ajax
to submit a form, but I want to add some key-value pairs to the submission that are not part of the form inputs. The technique of concatenating these extra parameters works fine but seems less elegant that using $.extend
. The trouble is I can't get the latter to work.
This works:
var data = $form.serialize() + "&a=1&b=0.5";
This does not:
var data = $.extend({}, $form.serialize(), {
a: 1,
b: 0.5
});
I can see when I inspect what is submitted in the case that works I have three key value pairs:
t:test
a:1
b:0.5
Where t
is the name of the single form input field (a text box).
When I use the $.extend
function, inspection reveals the following:
0:t
1:=
2:t
3:e
4:s
5:t
a:1
b:0.5
My application doesn't like this request. Is this behaviour to be expected or can somebody point out what I'm doing wrong?