CKEDITOR.ajax
Ajax methods for data loading.
Filtering
Methods
load( url, [ callback ], [ responseType ] ) → String | nullCKEDITOR.ajax#loadLoads 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 : StringThe URL from which the data is loaded.
[ callback ] : FunctionA callback function to be called on data load. If not provided, the data will be loaded synchronously.
[ responseType ] : StringDefines type of returned data. Currently supports:
text,xml,arraybuffer. This parameter was introduced in4.16.0.Defaults to
'text'
Returns
String | nullThe loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests -
null.
loadBinary( url, [ callback ] ) → ArrayBufferCKEDITOR.ajax#loadBinaryLoads 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 : StringThe URL from which the data is loaded.
[ callback ] : FunctionA callback function to be called on data load. If not provided, the data will be loaded synchronously.
Returns
ArrayBufferArrayBuffer storing the loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests -
null.
loadText( url, [ callback ] ) → StringCKEDITOR.ajax#loadTextLoads 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 : StringThe URL from which the data is loaded.
[ callback ] : FunctionA callback function to be called on data load. If not provided, the data will be loaded synchronously.
Returns
StringString storing the loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests -
null.
loadXml( url, [ callback ] ) → xmlCKEDITOR.ajax#loadXmlLoads 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 : StringThe URL from which the data is loaded.
[ callback ] : FunctionA callback function to be called on data load. If not provided, the data will be loaded synchronously.
Returns
xmlAn XML object storing the loaded data for synchronous request. For asynchronous requests - empty string. For invalid requests -
null.
-
Creates an asynchronous POST
XMLHttpRequestof the givenurl,dataand optionalcontentType. Once the request is done, regardless if it is successful or not, thecallbackis called withXMLHttpRequest#responseTextornullas 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 : StringThe URL of the request.
data : String | Object | ArrayData passed to
XMLHttpRequest#send.[ contentType ] : StringThe value of the
Content-typeheader.Defaults to
'application/x-www-form-urlencoded; charset=UTF-8'[ callback ] : FunctionA callback executed asynchronously with
XMLHttpRequest#responseTextornullas an argument, depending on thestatusof the request.