jQuery AJAX submit form

0 votes

I have with me a form with the name orderproductForm and an undefined number of inputs.

I would like to use some kind of  jQuery.get or ajax or anything like that which can call a page through Ajax, and send it along with all the inputs of the form orderproductForm.

I suppose one way would be to do something on the lines of the code mentioned below:-

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 and is there a feature, function or something that would just send all the form inputs?

Feb 8 in Java by Rahul
• 8,980 points
178 views

1 answer to this question.

0 votes

There is a simple input mentioned below which could be of your help:

// 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. 
    } 
  });
});
answered Feb 8 by Soham
• 8,730 points

Related Questions In Java

0 votes
1 answer

Wait until all jQuery Ajax requests are done?

You may need to run certain code ...READ MORE

answered May 30 in Java by gaurav
• 13,560 points
32 views
0 votes
1 answer

Google AJAX Libraries CDN for jQuery

The Google Hosted Libraries is a stable, ...READ MORE

answered May 30 in Java by gaurav
• 13,560 points
77 views
0 votes
2 answers

How can I invoke a method when the method name is in the form of a given string?

You could probably use method invocation from reflection: Class<?> ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 59,170 points
1,082 views
0 votes
1 answer

Use Servlets with Ajax

Here, we are going to create the ...READ MORE

answered Jul 16, 2018 in Java by Akrati
• 3,190 points
2,673 views
0 votes
0 answers

How to reset a form using jQuery with .reset() method

My code : <div id="labels"> <table class="config"> ...READ MORE

May 24 in Java-Script by Kichu
• 19,040 points
41 views
0 votes
0 answers

How can I upload files asynchronously with jQuery?

I would like to upload a file ...READ MORE

Jun 10 in JQuery by gaurav
• 13,560 points
17 views
0 votes
1 answer

How to reset a form using jQuery with .reset() method

<input type="reset"> Syntax for reset(): formObject.reset() Syntax to convert ...READ MORE

answered Jun 16 in JQuery by rajatha
• 5,040 points
15 views
0 votes
1 answer

Abort Ajax requests using jQuery

Instead of aborting, you can choose to ...READ MORE

answered Jun 16 in JQuery by rajatha
• 5,040 points
18 views
0 votes
1 answer

jQuery get value of select onChange

Try the following lines of code- $('select').on('change', function() ...READ MORE

answered Feb 11 in Java by Soham
• 8,730 points
106 views
0 votes
1 answer

jQuery UI " $("#datepicker").datepicker is not a function"

I struggled with a similar problem for ...READ MORE

answered Feb 17 in Java by Soham
• 8,730 points
989 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP