Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery AJAX submit form

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?

like image 621
Nathan H Avatar asked Dec 25 '09 01:12

Nathan H


People also ask

Can we submit form using AJAX?

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.

What is AJAX form submit?

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.

What is ajaxForm in jQuery?

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.


1 Answers

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.         }     });      }); 
like image 145
Alfrekjv Avatar answered Sep 27 '22 01:09

Alfrekjv