Report an issue
Class

CKEDITOR.ajax

class singleton

Ajax methods for data loading.

Filtering

Methods

  • load( url, [ callback ], [ responseType ] ) → String | null

    Loads data from a given URL.

    // Load data synchronously.
    var data = CKEDITOR.ajax.load( 'somedata.txt' );
    alert( data );
    
    // Load data asynchronously.
    var data = CKEDITOR.ajax.load( 'somedata.txt', function( data ) {
        alert( data );
    } );
    

    Parameters

    url : String

    The URL from which the data is loaded.

    [ callback ] : Function

    A callback function to be called on data load. If not provided, the data will be loaded synchronously.

    [ responseType ] : String

    Defines type of returned data. Currently supports: text, xml, arraybuffer. This parameter was introduced in 4.16.0.

    Defaults to 'text'

    Returns

    String | null

    The loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests - null.

  • loadBinary( url, [ callback ] ) → ArrayBuffer

    Loads data from a given URL as binary data.

    // Load data synchronously.
    var binaryData = CKEDITOR.ajax.loadBinary( 'somedata.png' );
    alert( binaryData );
    
    // Load data asynchronously.
    var data = CKEDITOR.ajax.loadBinary( 'somedata.png', function( binaryData ) {
        alert( binaryData );
    } );
    

    Parameters

    url : String

    The URL from which the data is loaded.

    [ callback ] : Function

    A callback function to be called on data load. If not provided, the data will be loaded synchronously.

    Returns

    ArrayBuffer

    ArrayBuffer storing the loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests - null.

  • loadText( url, [ callback ] ) → String

    Loads data from a given URL as text.

    // Load text synchronously.
    var text = CKEDITOR.ajax.loadText( 'somedata.txt' );
    alert( text );
    
    // Load text asynchronously.
    var data = CKEDITOR.ajax.loadText( 'somedata.txt', function( textData ) {
        alert( textData );
    } );
    

    Parameters

    url : String

    The URL from which the data is loaded.

    [ callback ] : Function

    A callback function to be called on data load. If not provided, the data will be loaded synchronously.

    Returns

    String

    String storing the loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests - null.

  • loadXml( url, [ callback ] ) → xml

    Loads data from a given URL as XML.

    // Load XML synchronously.
    var xml = CKEDITOR.ajax.loadXml( 'somedata.xml' );
    alert( xml.getInnerXml( '//' ) );
    
    // Load XML asynchronously.
    var data = CKEDITOR.ajax.loadXml( 'somedata.xml', function( xml ) {
        alert( xml.getInnerXml( '//' ) );
    } );
    

    Parameters

    url : String

    The URL from which the data is loaded.

    [ callback ] : Function

    A callback function to be called on data load. If not provided, the data will be loaded synchronously.

    Returns

    xml

    An XML object storing the loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests - null.

  • since 4.4

    post( url, data, [ contentType ], [ callback ] )

    Creates an asynchronous POST XMLHttpRequest of the given url, data and optional contentType. Once the request is done, regardless if it is successful or not, the callback is called with XMLHttpRequest#responseText or null as an argument.

    CKEDITOR.ajax.post( 'url/post.php', 'foo=bar', null, function( data ) {
        console.log( data );
    } );
    
    CKEDITOR.ajax.post( 'url/post.php', JSON.stringify( { foo: 'bar' } ), 'application/json', function( data ) {
        console.log( data );
    } );
    

    Parameters

    url : String

    The URL of the request.

    data : String | Object | Array

    Data passed to XMLHttpRequest#send.

    [ contentType ] : String

    The value of the Content-type header.

    Defaults to 'application/x-www-form-urlencoded; charset=UTF-8'

    [ callback ] : Function

    A callback executed asynchronously with XMLHttpRequest#responseText or null as an argument, depending on the status of the request.