AjaxTransport

Configs

1
transport: Object

Configuration 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:

ParameterTypeDescription
transport.loadObject

Load requests configuration:

transport.load.urlString

URL to request for data loading.

transport.load.methodString

HTTP method to be used for load requests.

transport.load.paramNameString

Name of the parameter that will contain a serialized load request. The value is mandatory for requests using GET method (default for load) so if the value is not provided data string is used as default. This value is optional for HTTP methods like POST and PUT, the request body will be used for data transferring in these cases.

transport.load.paramsObject

An object containing extra HTTP parameters to pass to the server when sending a load request.

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
        // so resulting URL will look like: http://mycool-server.com/load.php?userId=123456&data=...
        params    : {
            userId : '123456'
        }
    },
    ...
}
transport.load.headersObject<String, String>

An object containing headers to pass to each server request.

transport : {
    load : {
        url       : 'http://mycool-server.com/load.php',
        // HTTP request parameter used to pass serialized "load"-requests
        paramName : 'data',
        // specify Content-Type for "load" requests
        headers   : {
            'Content-Type' : 'application/json'
        }
    },
    ...
}
transport.syncObject

Sync requests (sync in further text) configuration:

transport.sync.urlString

URL to request for sync.

transport.sync.methodString

HTTP request method to be used for sync.

transport.sync.paramNameString

Name of the parameter in which sync data will be transferred. This value is optional for requests using methods like POST and PUT, the request body will be used for data transferring in this case (default for sync). And the value is mandatory for requests using GET method (if the value is not provided data string will be used as fallback).

transport.sync.paramsObject

HTTP parameters to pass with an HTTP request handling sync.

transport : {
    sync : {
        url    : 'http://mycool-server.com/sync.php',
        // extra HTTP request parameter
        params : {
            userId : '123456'
        }
    },
    ...
}
transport.sync.headersObject<String, String>

HTTP headers to pass with an HTTP request handling sync.

transport : {
    sync : {
        url     : 'http://mycool-server.com/sync.php',
        // specify Content-Type for "sync" requests
        headers : {
            'Content-Type' : 'application/json'
        }
    },
    ...
}

Properties

2
isAjaxTransport: Boolean= truereadonly
Identifies an object as an instance of AjaxTransport class, or subclass thereof.
isAjaxTransport: Boolean= truereadonlystatic
Identifies an object as an instance of AjaxTransport class, or subclass thereof.

Functions

2

Cancels an ongoing request.

ParameterTypeDescription
requestPromisePromise

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.

ParameterTypeDescription
requestObject

The request configuration object having following properties:

request.typeload | sync

The request type. Either load or sync.

request.urlString

The URL for the request. Overrides the URL defined in the transport object

request.dataString

The encoded Crud Manager request data.

request.paramsObject

An object specifying extra HTTP params to send with the request.

request.successfunction

A function to be started on successful request transferring.

request.success.rawResponseString

Response object returned by the fetch api.

request.failurefunction

A function to be started on request transfer failure.

request.failure.rawResponseString

Response object returned by the fetch api.

request.thisObjObject

this reference for the above success and failure functions.

Returns: Promise -

The fetch Promise object.

Events

1

Fires 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 }) => {

});
ParameterTypeDescription
crudManagerAbstractCrudManager

The CRUD manager.

paramsObject

HTTP request params to be passed in the request URL.

requestTypesync | load

CrudManager request type (load/sync)

requestConfigObject

Configuration object for Ajax request call

Event handlers

1

Called 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 }) {

    }
});
ParameterTypeDescription
crudManagerAbstractCrudManager

The CRUD manager.

paramsObject

HTTP request params to be passed in the request URL.

requestTypesync | load

CrudManager request type (load/sync)

requestConfigObject

Configuration object for Ajax request call