PrizmDoc® Viewer v13.28 Release - Updated
PrizmDoc Viewer / API Reference / Viewer Control / Namespace: PCCViewer / Namespace: Ajax
In This Topic
    Namespace: Ajax
    In This Topic

    PCCViewer. Ajax

    This object provides some helper methods that allow you to make and filter Ajax requests.

    Members

    headers :string

    Gets or sets the headers that will be defined with every AJAX request Viewer Control makes.

    This is an ECMA 5 property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8. For the greatest browser compatibility, use the corresponding getter and setter methods.

    Example

    // get
    var headers = PCCViewer.Ajax.headers;
    
    // set
    PCCViewer.Ajax.headers = { 'My-Secret-Header': 'mysecretkey' };
    
    

    Type:

    • string
    See:

    overrideMethod :string

    Gets or sets the overrideMethod that will be defined with every AJAX request Viewer Control makes.

    This is an ECMA 5 property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8. For the greatest browser compatibility, use the corresponding getter and setter methods.

    Example

    // get
    var overrideMethod = PCCViewer.Ajax.overrideMethod;
    
    // set
    PCCViewer.Ajax.overrideMethod = function(options) {
        options.headers['My-Secret-Header'] = 'mysecretkey';
    };
    
    

    Type:

    • string
    See:

    Methods

    getHeaders() → {Object}

    Gets the headers object that will be sent with every request.

    Note: Any header returned here will be sent with the request as long as the specific request doesn't use that same header with a different value. If you're expecting the header to exist on all requests, it should use a unique key that is not used by Accusoft. Certain mandatory headers required by every request will not be returned from this method. See PCCViewer.Ajax#setHeaders for this list of inaccessible headers.

    Example

    // The default headers are set for every request
    PCCViewer.Ajax.setHeaders({
        'My-Secret-Header': 'mysecretkey',
        'Authorization': 'Token asdf1234'
    });
    
    // Retrieve the headers that have previously been set
    PCCViewer.Ajax.getHeaders(); // returns { 'My-Secret-Header': 'mysecretkey', 'Authorization': 'Token asdf1234' }
    
    
    See:

    Returns:

    A copy of the headers object set with PCCViewer.Ajax#setHeaders.

    Type
    Object

    getOverrideMethod() → {function}

    Gets the override method that will be called with every request.

    Note: The function that is returned with this object is passed by reference and is the same one set with setOverrideMethod. Use caution when interacting with it.

    Example

    // A function is set to add a header to every request
    PCCViewer.Ajax.setOverrideMethod(function(options) {
        options.headers['My-Secret-Header'] = 'mysecretkey';
    });
    
    // Retrieve the override method that was previously set
    PCCViewer.Ajax.getOverrideMethod(); // returns function
    
    
    See:

    Returns:

    The function defined with PCCViewer.Ajax#setOverrideMethod.

    Type
    function

    setHeaders(headers) → {Object}

    Sets the headers object that will be sent with every request.

    Notes:

    • Overwrites any headers already set except the mandatory headers listed below.
    • The mandatory headers are: Accusoft-Gid, Accusoft-Parent-Name, Accusoft-Parent-Pid, and Accusoft-Parent-Taskid.
    • Setting the headers as undefined will result in no additional headers being sent with every request. The headers that the request requires will still be present, including the listed mandatory headers.

    Example

    // getHeaders() returns an empty object if setHeaders() has not been called
    PCCViewer.Ajax.getHeaders(); // returns {}
    
    // After calling setHeaders() with an object, getHeaders() will return a copy of that object
    PCCViewer.Ajax.setHeaders({ 'My-Secret-Header', 'mysecretkey' });
    PCCViewer.Ajax.getHeaders(); // returns { 'My-Secret-Header', 'mysecretkey' }
    
    // After calling setHeaders() without any arguments, getHeaders() will return an empty object
    PCCViewer.Ajax.setHeaders();
    PCCViewer.Ajax.getHeaders(); // returns {}
    
    // The value can only be set to an object or undefined.
    // All other data types throw.
    PCCViewer.Ajax.setHeaders(null); // throws
    PCCViewer.Ajax.setHeaders(1);    // throws
    PCCViewer.Ajax.setHeaders(true); // throws
    PCCViewer.Ajax.setHeaders('b');  // throws
    PCCViewer.Ajax.setHeaders([]);   // throws
    
    

    Parameters:

    Name Type Description
    headers Object

    An object containing the headers we will send with every request.

    • This must be an object or undefined.
    See:

    Throws:

    • If headers is not an object or undefined.

      Type
      Error
    • If headers attempts to overwrite a mandatory header. See the Notes section for more information.

      Type
      Error

    Returns:

    The PCCViewer.Ajax object.

    Type
    Object

    setOverrideMethod(method) → {Object}

    Sets the override method that will be called with every request.

    Notes:

    • Overwrites any method already set.
    • Setting the method as undefined will result in no override taking place. The request will proceed as usual

    Example

    // getOverrideMethod() returns undefined if setOverrideMethod() has not been called
    PCCViewer.Ajax.getOverrideMethod(); // returns undefined
    
    // After calling setOverrideMethod() with a function, getOverrideMethod() will return the function by reference
    PCCViewer.Ajax.setOverrideMethod(function(options) { options.url = 'http://accusoft.com/'; });
    PCCViewer.Ajax.getOverrideMethod(); // returns function
    
    // After calling setOverrideMethod() without any arguments, getOverrideMethod() will return undefined
    PCCViewer.Ajax.setOverrideMethod();
    PCCViewer.Ajax.getOverrideMethod(); // returns undefined
    
    // The value can only be set to a function or undefined.
    // All other data types throw.
    PCCViewer.Ajax.setOverrideMethod(null); // throws
    PCCViewer.Ajax.setOverrideMethod(1);    // throws
    PCCViewer.Ajax.setOverrideMethod(true); // throws
    PCCViewer.Ajax.setOverrideMethod('b');  // throws
    PCCViewer.Ajax.setOverrideMethod([]);   // throws
    
    

    Parameters:

    Name Type Description
    method PCCViewer.Ajax~OverrideMethod

    A function that will be called with every request that allows you to override or modify the request.

    • This must be a function or undefined.
    See:

    Throws:

    If method is not a function or undefined.

    Type
    Error

    Returns:

    The PCCViewer.Ajax object.

    Type
    Object

    Type Definitions

    OverrideMethod(options) → {Promise|Undefined}

    The function that you define with PCCViewer.Ajax#setOverrideMethod should follow this format

    Example

    // This method can modify properties of the original request
    PCCViewer.Ajax.setOverrideMethod(function(options) {
        options.url = 'http://accusoft.com/';
    });
    
    // This method can prevent default execution from continuing
    PCCViewer.Ajax.setOverrideMethod(function(options) {
        var deferred = $.Deferred();
    
        $.ajax({
            url: options.url,
            method: options.method,
            headers: options.headers,
            data: options.body,
            mimeType: options.mimeType,
            timeout: options.timeout,
        }).then(
            function(data, textStatus, jqXHR) {
                deferred.resolve(new PCCViewer.AjaxResponse({
                    status: jqXHR.status,
                    statusText: textStatus,
                    headers: {
                        'Fake-Header': 'thisisnotreal'
                    },
                    responseText: jqXHR.responseText,
                }));
            },
            function(jqXHR, textStatus, errorThrown) {
                deferred.reject({
                    error: new PCCViewer.Error('Error', errorThrown),
                    response: new PCCViewer.AjaxResponse({
                        status: jqXHR.status,
                        statusText: textStatus,
                        headers: {
                            'Fake-Header': 'thisisnotreal'
                        },
                        responseText: jqXHR.responseText,
                    }),
                });
            }
        );
    
        return deferred.promise();
    });
    
    

    Parameters:

    Name Type Description
    options Object
    Properties
    Name Type Attributes Default Description
    url String
    method String <optional>
    "GET"
    headers Object <optional>
    {}
    body String <optional>
    null
    timeout Number <optional>
    null
    mimeType String <optional>
    null
    • The mime type used for the response, overriding what the server sends. See: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#overrideMimeType()
    See:

    Returns:

    • Optionally returns a then-able object (Promise) to prevent default execution from continuing.
    Type
    Promise | Undefined

    Documentation generated by JSDoc 3.6.10 on Thu Oct 31 2024 15:05:54 GMT+0000 (Coordinated Universal Time)