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, 2022 in Java by Rahul
• 9,680 points
1,656 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, 2022 by Soham
• 9,710 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, 2022 in Java by gaurav
• 23,260 points
16,788 views
0 votes
1 answer

Google AJAX Libraries CDN for jQuery

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

answered May 30, 2022 in Java by gaurav
• 23,260 points
1,595 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,230 points
3,074 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
3,827 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, 2022 in Java-Script by Kichu
• 19,040 points
736 views
0 votes
0 answers

How can I upload files asynchronously with jQuery?

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

Jun 10, 2022 in JQuery by gaurav
• 23,260 points
653 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, 2022 in JQuery by rajatha
• 7,680 points
15,716 views
0 votes
1 answer

Abort Ajax requests using jQuery

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

answered Jun 16, 2022 in JQuery by rajatha
• 7,680 points
764 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, 2022 in Java by Soham
• 9,710 points
21,914 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, 2022 in Java by Soham
• 9,710 points
6,396 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP