Ajax
Revision as of 11:10, 3 October 2023 by 99.255.206.241 (talk)
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