Skip to Content
NFSFU234FormValidation v3 is here — file upload validation, config-driven rules, and more.

ajax

Instance version of NFSFU234FormValidation.ajax. Sends an AJAX request using the supplied request configuration.

The returned Promise is also stored internally so it can later be retrieved with (). Returns: Promise<any>

ParameterTypeRequiredDefaultDescription
AJAXOptionsAJAXOptionsInterfacerequired-The request configuration, including the URL, HTTP method, headers, and request body.
Usage
Example 1: GET Request
const AJAXOptions = { url: 'https://your-api-endpoint.tld', // URL for the AJAX request RequestMethod: 'GET', // Request method RequestHeader: { 'Content-Type': 'application/json', // Example request header // Add other request headers if needed }, RequestBodyIgnore: true }; nfsfu234FormValidation.ajax(AJAXOptions) .then((response) => { // Success: Server response received in JSON format console.log('Request successful', response); }) .catch((error) => { // Error: AJAX request failed or rejected console.error('Request failed', error); });
Example 2: POST Request
const AJAXOptions = { url: 'https://your-api-endpoint.tld', // URL for the AJAX request RequestMethod: 'POST', // Request method RequestHeader: { 'Content-Type': 'application/json', // Example request header // Add other request headers if needed }, RequestBody: { title: 'new product', price: 29.99, description: 'A great product', image: 'https://i.pravatar.cc', category: 'electronics' } }; nfsfu234FormValidation.ajax(AJAXOptions) .then((response) => { // Success: Server response received in JSON format console.log('Request successful', response); }) .catch((error) => { // Error: AJAX request failed or rejected console.error('Request failed', error); });
Last updated on