I would like to use jQuery.ajax to submit a form using POST without having to specify everything manually in the "data: " part.
This is what I don't want:
data: "username=" + document.getElementById("username").value +
"&email=" + document.getElementById("email").value,
Is there a way to just have it include alla elements with their values from an entire FORM field? This form is generated dynamically so it would save me a lot of time!
Use serialize method.
data : $("form").serialize()
Look at http://docs.jquery.com/Ajax/serialize.
That would make the following example:
$("#submit").click(function() {
$.ajax({
data: $("form").serialize(),
...rest
});
});
Use .serialize()
method to send entire form data in jQuery Ajax.
data:$('#formID').serialize()
Example script can be found from here - How to send entire form data in jQuery Ajax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With