Skip to content
Fix Code Error

jQuery AJAX submit form

March 13, 2021 by Code Error
Posted By: Anonymous

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?

Solution

You can use the ajaxForm/ajaxSubmit functions from Ajax Form Plugin or the jQuery serialize function.

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.

Answered By: Anonymous

Related Articles

  • NOT IN vs NOT EXISTS
  • How to make JQuery-AJAX request synchronous
  • How to define Typescript Map of key value pair. where key is…
  • jQuery Mobile: document ready vs. page events
  • Ember.js View Binding Not Working?
  • T-SQL How to create tables dynamically in stored procedures?
  • When I delete multiple product in my basket only first…
  • deleting products from database and reloading into stock
  • MySQL - sum column value(s) based on row from the same table
  • How do SO_REUSEADDR and SO_REUSEPORT differ?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do I merge two dictionaries in a single expression (taking union of dictionaries)?

Next Post:

Fastest way to check if a value exists in a list

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error