Class AuWidgetAjax
A non-visual widget that is used to send requests to the server and receive responses, which can be used in other widgets. For details, see the Ajax widget topic.
The following example illustrates how you can populate a gallery with images obtained through an HTTP request.
{
"widgets": [
{
"name": "bg-request",
"type": "ajax",
"params": {
"lock": "gallery",
"url": "{{vars.apiUrl + '/api/images?subfolder=backgrounds'}}",
"method": "GET",
"responseType": "json"
}
},
{
"name": "gallery",
"title": "Gallery",
"type": "gallery",
"params": {
"prompt": "Set a background",
"showTitle": false,
"forceSelection": true,
"items": "{{ $['bg-request'].response.items }}"
}
}
]
}
Package: ui-framework
Properties
enabled
If false, the request will not be executed. The default value is true.
Declaration
public enabled: boolean = true
Property Value
| Type | Description |
|---|---|
| boolean | If |
error
Declaration
public error: any = null
Property Value
| Type | Description |
|---|---|
| any |
headers
A dictionary of HTTP headers sent along with the request (an object with the keys used as a header name and a value used as a header value).
Declaration
public headers: any
Property Value
| Type | Description |
|---|---|
| any | A dictionary of HTTP headers sent along with the request (an object with the keys used as a header name and a value used as a header value). |
method
An HTTP method like POST, GET, etc. The default value is POST.
Declaration
public method: string = "POST"
Property Value
| Type | Description |
|---|---|
| string | An HTTP method like |
params
Parameters of the Ajax widget.
Declaration
public params: IAuWidgetAjaxConfig
Property Value
| Type | Description |
|---|---|
| IAuWidgetAjaxConfig | Parameters of the |
request
A request body. Typically, you put a JSON here that consists of references to other widgets.
Declaration
public request: any
Property Value
| Type | Description |
|---|---|
| any | A request body. Typically, you put a JSON here that consists of references to other widgets. |
requestPromise
Promise, for awaiting in #function for getting response.
"{{ #function $['image-request'].compile() }}",
"{{ #asyncFunction await $['image-request'].requestPromise }}"
Declaration
public requestPromise: Promise<any> = Promise.resolve()
Property Value
| Type | Description |
|---|---|
| Promise<any> | Promise, for awaiting in #function for getting response.
|
requests
Declaration
public requests: Array<any>
Property Value
| Type | Description |
|---|---|
| Array<any> |
response
A server response, interpreted based on the responseType param. If autoCompile is true, it is automatically updated every time the widget gets a server response.
Declaration
public response: any
Property Value
| Type | Description |
|---|---|
| any | A server response, interpreted based on the responseType param. If |
responseHeaders
Declaration
public responseHeaders: Headers = null
Property Value
| Type | Description |
|---|---|
| Headers |
responses
Declaration
public responses: any = []
Property Value
| Type | Description |
|---|---|
| any |
responseType
Defines how to interpret the response received from the server.
Declaration
public responseType: ResponseType = "json"
Property Value
| Type | Description |
|---|---|
| ResponseType | Defines how to interpret the response received from the server. |
statusCode
Declaration
public statusCode: number = null
Property Value
| Type | Description |
|---|---|
| number |
template
Declaration
static HTMLTemplateElement template
Property Value
| Type | Description |
|---|---|
| HTMLTemplateElement |
url
A URL that is used to accept requests.
Declaration
public url: string
Property Value
| Type | Description |
|---|---|
| string | A URL that is used to accept requests. |
Methods
checkInitDependenciesWidgets()
Returns an array of widget names, due to which the current widget cannot receive parameters.
Declaration
function checkInitDependenciesWidgets()
Returns
| Type | Description |
|---|---|
| string[] |
exportWidgetData(boolean)
Declaration
function exportWidgetData(force: boolean)
Parameters
| Type | Name | Description |
|---|---|---|
| boolean | force |
Returns
| Type | Description |
|---|---|
| Promise<AjaxWidgetData> |
resetPreloaderState()
Declaration
function resetPreloaderState()
restoreWidgetFromData(AjaxWidgetData, boolean)
Declaration
function restoreWidgetFromData(widgetData: AjaxWidgetData, force: boolean)
Parameters
| Type | Name | Description |
|---|---|---|
| AjaxWidgetData | widgetData | |
| boolean | force |
Returns
| Type | Description |
|---|---|
| Promise<void> |
showPreloader(boolean)
Shows a preloader.
Declaration
function showPreloader(isShow: boolean)
Parameters
| Type | Name | Description |
|---|---|---|
| boolean | isShow |
If |
showToast(string, number)
Shows a toast.
return editor.loadUserInfo(data)
.catch(err => {
this.widget.showToast("Error: Invalid data");
console.log(err);
});
Declaration
function showToast(data?: string, duration?: number)
Parameters
| Type | Name | Description |
|---|---|---|
| string | data |
A string message to display in the toast. |
| number | duration |
Defines how long to show the toast for. |