I have a form with name orderproductForm
and an undefined number of inputs.
I want to do some kind of jQuery.get or ajax or anything like that that would call a page through Ajax, and send along all the inputs of the form orderproductForm
.
I suppose one way would be to do something like
jQuery.get("myurl", {action : document.orderproductForm.action.value, cartproductid : document.orderproductForm.cartproductid.value, productid : document.orderproductForm.productid.value, ...
However I do not know exactly all the form inputs. Is there a feature, function or something that would just send ALL the form inputs?
We can submit a form by ajax using submit button and by mentioning the values of the following parameters. type: It is used to specify the type of request. url: It is used to specify the URL to send the request to. data: It is used to specify data to be sent to the server.
AJAX form submitting allows you to send data in the background, eliminating the need to reload websites to see the updates. This makes the user experience much smoother.
Overview. The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX . The main methods, ajaxForm and ajaxSubmit , gather information from the form element to determine how to manage the submit process.
This is a simple reference:
// this is the id of the form $("#idForm").submit(function(e) { e.preventDefault(); // avoid to execute the actual submit of the form. var form = $(this); var actionUrl = form.attr('action'); $.ajax({ type: "POST", url: actionUrl, data: form.serialize(), // serializes the form's elements. success: function(data) { alert(data); // show response from the php script. } }); });
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