Submit Any Form Via Ajax
Recently, I needed to use Ajax to send form information to a script on a server.
The form fields were unpredictable. Sometimes there may have been an email field and sometimes not, for example. Sometimes the form had dozens of fields to submit, sometimes only a few.
Further, there were some form fields that should not be sent to the script (fields used for determining the content of other fields, like math formulas).
The requirement led me to create a simple JavaScript function for submitting a form via Ajax — without knowing in advance what the form fields would be.
What is Ajax?
Ajax is a tool programmed with JavaScript. The tool is used to send information to and get information from URLs. The way it connects to the URLs is with HTTP or HTTPS, the same methods that browsers use.
What makes Ajax special is that it can use HTTP/S to connect to other web pages or software on the internet from within the web page already loaded in the browser.
Thus, Ajax can be used to send form information to a PHP script on the server — without reloading the web page that has the form.
When Ajax is used to send form information to a server script, the form field names generally are specified within the Ajax source code. Yet when, as in the situation described above, the form fields are not known ahead of time and might change from page load to page load, form field names can not be specified with acceptable accuracy.
Another way had to be found. That method is what this article is about.
The online article goes into more detail. It also provides a simple little PHP script you can use for testing your Ajax.
Thank you for reading Possibilities.
Recent additions to the Willmaster Blog and Library
We suggest and recommend only what we believe is of value. As remuneration for the time and research involved to provide quality material, we sometimes use affiliate links. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.
Addresses, URLs, and Subscription Maintenance:
Click to unsubscribe:
https://www.willmaster.com/possibilities/cmfposs/possmailer_unsubscribe.php?0f452844c528f36b84dcfc5074560ba0
To subscribe: https://www.willmaster.com/possibilities/
Changing email address: First unsubscribe your old address, then subscribe with your new email address.
Will Bontrager Software LLC, Publishers
P.O. Box 153
Lowell, IN 46356
USA
Copyright 2022 Will Bontrager Software LLC
Subscription Record:
Please Note: We do not make our mailing lists publicly accessible. Privacy is precious. We respect yours.
Subscription information:
Email: you
To remove your subscription (to unsubscribe), use this link:
https://www.willmaster.com/possibilities/cmfposs/possmailer_unsubscribe.php?0f452844c528f36b84dcfc5074560ba0