My $.ajax() is not serializing the button name and value.
I have a very simple form. It has a button and a textbox.
I like @slashingweapon 's approach, but why not even shorter, like this?
$("button.positive").click(function () {
var result = $(this).parents('form').serialize()
+ '&'
+ this.name
+ '='
+ this.value
;
console.log(result);
return false; // prevent default
});
Only if the server generates non-ascii button names or values, it would be like this:
$("button.positive").click(function () {
var result = $(this).parents('form').serialize()
+ '&'
+ encodeURI(this.name)
+ '='
+ encodeURI(this.value)
;
console.log(result);
return false; // prevent default
});