patternjavascriptCritical
jQuery AJAX submit form
Viewed 0 times
jqueryformajaxsubmit
Problem
I have a form with name
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
I suppose one way would be to do something like
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?
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?
Solution
You can use the ajaxForm/ajaxSubmit functions from Ajax Form Plugin or the jQuery serialize function.
AjaxForm:
or
ajaxForm will send when the submit button is pressed. ajaxSubmit sends immediately.
Serialize:
AJAX serialization documentation is here.
AjaxForm:
$("#theForm").ajaxForm({url: 'server.php', type: 'post'})or
$("#theForm").ajaxSubmit({url: 'server.php', type: 'post'})ajaxForm will send when the submit button is pressed. ajaxSubmit sends immediately.
Serialize:
$.get('server.php?' + $('#theForm').serialize())
$.post('server.php', $('#theForm').serialize())AJAX serialization documentation is here.
Code Snippets
$("#theForm").ajaxForm({url: 'server.php', type: 'post'})$("#theForm").ajaxSubmit({url: 'server.php', type: 'post'})$.get('server.php?' + $('#theForm').serialize())
$.post('server.php', $('#theForm').serialize())Context
Stack Overflow Q#1960240, score: 871
Revisions (0)
No revisions yet.