Reputation: 2194
Using either Javascript and/or Jquery how can I append POST data to a form to submit. I have in my server side code that will check to see if the post data dictionary contains a certain key.
I already have a form in the code. So I would just like to use javascript to add a new key to the POST data.
Upvotes: 1
Views: 6026
Reputation: 2894
quick example
you can add hidden inputs, for example:
var yourValue = 123;
$('form').append('<input type="hidden" id="yourData" name="yourData" value="'+ yourValue +'"/>');
so you get:
<input type="hidden" id="yourData" name="yourData" value="123"/>
and when you do the submit you are sending "yourData"
Upvotes: 3
Reputation: 1931
with jQuery:
var $input = $('<input>').attr(
{
type: 'hidden',
id: 'input_id',
name: 'input_name',
value: 'input_value'
}).appendTo('#form_name');
$('#form_name').submit();
is this what you were trying to do?
Upvotes: 3
Reputation: 3776
try to intercept the submit event and:
$.post(url, data, function(){});
function.Upvotes: 1