CKEDITOR.ajax
Ajax methods for data loading.
Filtering
Methods
-
load( url, [ callback ], [ responseType ] ) → String | null
CKEDITOR.ajax#load
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 in4.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
CKEDITOR.ajax#loadBinary
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
CKEDITOR.ajax#loadText
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
CKEDITOR.ajax#loadXml
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
.
-
Creates an asynchronous POST
XMLHttpRequest
of the givenurl
,data
and optionalcontentType
. Once the request is done, regardless if it is successful or not, thecallback
is called withXMLHttpRequest#responseText
ornull
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
ornull
as an argument, depending on thestatus
of the request.