https://stackoverflow.com/questions/1960240/jquery-ajax-submit-form
884
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?
add a comment
1318
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 url = form.attr('action');
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
});
I hope it helps you.
'frameworks > jQuery' 카테고리의 다른 글
ajax에서 송신 전처리, 후처리해서 loading 이미지 띄우기 : ajaxStart/ajaxStop, ajaxStart/ajaxStop무효화하기 (0) | 2019.10.13 |
---|
$("#idForm").submit(...)
rather than$("#submitButtonId").click(...)
– Renato Feb 12 '13 at 12:54return false
you should be usinge.preventDefault()
to allow further event propagation after your click handler is complete. Usinge.preventDefault()
will only stop the default action of the Submit button (e.g. to submit the form) but will allow any other events bound to that form to execute. See: fuelyourcoding.com/jquery-events-stop-misusing-return-false – John Kary Jun 3 '13 at 8:06data: $(this).serialize(),
instead ofdata: $("#idForm").serialize(),
which enables us to specify which form in just one location. – beingalex Jul 2 '14 at 14:15