Possible Duplicate:
submitting form and variables together through jquery
I am using following code to send form data to the server through ajax, jquery:
// this is the id of the submit button
$("#submitButtonId").click(function() {
var url = "path/to/your/script.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
If i have to send a parameter/value of my own other than the post form data, how can i do it?
Thanks.
There are a few ways that can be done.
Either you add a hidden field to the form with the name and value that you need to send. Then that field will be serialized as well when the form is serialized.
Another way would be to add your content at the end of the serialized form-data