Ajax: Difference between revisions

From Bitnami MediaWiki
Jump to navigation Jump to search
(Created page with "<strong>Create new axios instance.</strong> Add the following import: <pre>import axiosWrapper, { BusinessResult } from '@/common-axios'; This returns a singleton of the AxiosWrapper class, which is a class the wraps the calls to the Novus web service and internally uses the axios object. The BusinessResult class is a common class to return for POST requests to check if operation was successful or not: this.postData<BusinessResult>('foo', postData) .then((result) => {...")
 
No edit summary
Line 27: Line 27:
});
});
</pre>
</pre>
<strong>Return to [[Programming Guide]]</strong>

Revision as of 11:10, 3 October 2023

Create new axios instance. Add the following import:

import axiosWrapper, { BusinessResult } from '@/common-axios';

This returns a singleton of the AxiosWrapper class, which is a class the wraps the calls to the Novus web service and internally uses the axios object. The BusinessResult class is a common class to return for POST requests to check if operation was successful or not:

this.postData<BusinessResult>('foo', postData)
.then((result) => {
  this.shellModule.setShowLoading(false);
  result = BusinessResult.fromJson(result);

  if (result.ResultStatus !== BusinessResult.StatusSuccess) {
    this.showGenericModal(result.Message || '', 'Error');
    return;
  }

Example axios call:

return new Promise<BusinessResult>((resolve, reject) =>
{
  axiosWrapper.post<BusinessResult>('api/foo/bar', postData)
  .then((response) => {
    resolve(response.data);
  })
  .catch(() => reject());
});

Return to Programming Guide