AjaxTransport
Configs
1
Configs
1Configuration of the AJAX requests used by Crud Manager to communicate with a server-side.
transport : {
load : {
url : 'http://mycool-server.com/load.php',
// HTTP request parameter used to pass serialized "load"-requests
paramName : 'data',
// pass extra HTTP request parameter
params : {
foo : 'bar'
}
},
sync : {
url : 'http://mycool-server.com/sync.php',
// specify Content-Type for requests
headers : {
'Content-Type' : 'application/json'
}
}
}
Since the class uses Fetch API you can use any of the Request interface options:
transport : {
load : {
url : 'http://mycool-server.com/load.php',
// HTTP request parameter used to pass serialized "load"-requests
paramName : 'data',
// pass few Fetch API options
method : 'GET',
credentials : 'include',
cache : 'no-cache'
},
sync : {
url : 'http://mycool-server.com/sync.php',
// specify Content-Type for requests
headers : {
'Content-Type' : 'application/json'
},
credentials : 'include'
}
}
An object where you can set the following possible properties:
| Parameter | Type | Description |
|---|---|---|
transport.load | Object | Load requests configuration: |
transport.load.url | String | URL to request for data loading. |
transport.load.method | String | HTTP method to be used for load requests. |
transport.load.paramName | String | Name of the parameter that will contain a serialized |
transport.load.params | Object | An object containing extra HTTP parameters to pass to the server when
sending a |
transport.load.headers | Object<String, String> | An object containing headers to pass to each server request. |
transport.sync | Object | Sync requests ( |
transport.sync.url | String | URL to request for |
transport.sync.method | String | HTTP request method to be used for |
transport.sync.paramName | String | Name of the parameter in which |
transport.sync.params | Object | HTTP parameters to pass with an HTTP request handling |
transport.sync.headers | Object<String, String> | HTTP headers to pass with an HTTP request handling |
Properties
2
Properties
2Functions
2
Functions
2Cancels an ongoing request.
| Parameter | Type | Description |
|---|---|---|
requestPromise | Promise | The Promise object wrapping the Request to be cancelled. The requestPromise is the value returned from the corresponding sendRequest call. |
Sends a Crud Manager request to the server.
| Parameter | Type | Description |
|---|---|---|
request | Object | The request configuration object having following properties: |
request.type | load | sync | The request type. Either |
request.url | String | The URL for the request. Overrides the URL defined in the |
request.data | String | The encoded Crud Manager request data. |
request.params | Object | An object specifying extra HTTP params to send with the request. |
request.success | function | A function to be started on successful request transferring. |
request.success.rawResponse | String |
|
request.failure | function | A function to be started on request transfer failure. |
request.failure.rawResponse | String |
|
request.thisObj | Object |
|
The fetch Promise object.
Events
1
Events
1Fires before a request is sent to the server.
crudManager.on('beforeSend', function ({ params, type }) {
// let's set "sync" request parameters
if (type == 'sync') {
// dynamically depending on "flag" value
if (flag) {
params.foo = 'bar';
}
else {
params.foo = 'smth';
}
}
});
// Adding a listener using the "on" method
ajaxTransport.on('beforeSend', ({ crudManager, params, requestType, requestConfig }) => {
});| Parameter | Type | Description |
|---|---|---|
crudManager | AbstractCrudManager | The CRUD manager. |
params | Object | HTTP request params to be passed in the request URL. |
requestType | sync | load | CrudManager request type ( |
requestConfig | Object | Configuration object for Ajax request call |
Event handlers
1
Event handlers
1Called before a request is sent to the server.
crudManager.on('beforeSend', function ({ params, type }) {
// let's set "sync" request parameters
if (type == 'sync') {
// dynamically depending on "flag" value
if (flag) {
params.foo = 'bar';
}
else {
params.foo = 'smth';
}
}
});
new AjaxTransport({
onBeforeSend({ crudManager, params, requestType, requestConfig }) {
}
});| Parameter | Type | Description |
|---|---|---|
crudManager | AbstractCrudManager | The CRUD manager. |
params | Object | HTTP request params to be passed in the request URL. |
requestType | sync | load | CrudManager request type ( |
requestConfig | Object | Configuration object for Ajax request call |