Important changes to Tiny Cloud pricing > Find out more

NOTE: TinyMCE 5 reached End of Support in April 2023. No more bug fixes, security updates, or new features will be introduced to TinyMCE 5. We recommend you upgrade to TinyMCE 6 or consider TinyMCE 5 Long Term Support (LTS) if you need more time.

tinymce.util.XHR

This API allows you to send XMLHTTPRequests cross browser. Extends the Observable class.

XHR has been deprecated in TinyMCE 5.10 and has been marked for removal in TinyMCE 6.0.

Examples

// Sends a low level Ajax request
tinymce.util.XHR.send({
   url: 'someurl',
   success: function(text) {
      console.debug(text);
   }
});

// Add custom header to XHR request
tinymce.util.XHR.on('beforeSend', function(e) {
    e.xhr.setRequestHeader('X-Requested-With', 'Something');
});

Methods

name summary defined by
fire() Fires the specified event by name. Consult the event reference for more details on each event. tinymce.util.Observable
hasEventListeners() Returns true/false if the object has a event of the specified name. tinymce.util.Observable
off() Unbinds an event listener to a specific event by name. Consult the event reference for more details on each event. tinymce.util.Observable
on() Binds an event listener to a specific event by name. Consult the event reference for more details on each event. tinymce.util.Observable
once() Bind the event callback and once it fires the callback is removed. Consult the event reference for more details on each event. tinymce.util.Observable
send() Sends a XMLHTTPRequest. tinymce.util.XHR

Methods

fire

fire(name:String, args:Object?, bubble:Boolean?):Object

Fires the specified event by name. Consult the event reference for more details on each event.

Examples
instance.fire('event', {...});
Parameters
  • name (String) - Name of the event to fire.
  • args (Object?) - Event arguments.
  • bubble (Boolean?) - True/false if the event is to be bubbled.
Return value
  • Object - Event args instance passed in.

hasEventListeners

hasEventListeners(name:String):Boolean

Returns true/false if the object has a event of the specified name.

Parameters
  • name (String) - Name of the event to check for.
Return value
  • Boolean - true/false if the event exists or not.

off

off(name:String?, callback:callback?):Object

Unbinds an event listener to a specific event by name. Consult the event reference for more details on each event.

Examples
// Unbind specific callback
instance.off('event', handler);

// Unbind all listeners by name
instance.off('event');

// Unbind all events
instance.off();
Parameters
  • name (String?) - Name of the event to unbind.
  • callback (callback?) - Callback to unbind.
Return value
  • Object - Current class instance.

on

on(name:String, callback:callback, prepend:Boolean):Object

Binds an event listener to a specific event by name. Consult the event reference for more details on each event.

Examples
instance.on('event', function(e) {
    // Callback logic
});
Parameters
  • name (String) - Event name or space separated list of events to bind.
  • callback (callback) - Callback to be executed when the event occurs.
  • prepend (Boolean) - Optional flag if the event should be prepended. Use this with care.
Return value
  • Object - Current class instance.

once

once(name:String, callback:callback):Object

Bind the event callback and once it fires the callback is removed. Consult the event reference for more details on each event.

Parameters
  • name (String) - Name of the event to bind.
  • callback (callback) - Callback to bind only once.
Return value
  • Object - Current class instance.

send

send(settings:Object)

Sends a XMLHTTPRequest.

Parameters
  • settings (Object) - An object containing the target URL, callbacks, and other information needed to make the request. For information on valid settings, see the table below.

    Setting Required/
    Optional
    Type Description

    url

    Required

    string

    Address to send the request to, such as the back-end server.

    async

    Optional

    boolean

    When false, the request will be synchronous. Set to true by default. NOTE: Synchronous requests have been deprecated on some browsers. For details, see: MDN Web Docs - XMLHttpRequest.open() Syntax.

    content_type

    Optional

    string

    Used to define the mime-type of the data. Similar to the XMLHttpRequest.overrideMimeType method.

    crossDomain

    Optional

    boolean

    When true, the withCredentials property will be set to true. For information on the withCredentials property, see: MDN Web Docs - XMLHttpRequest.withCredentials.

    data

    Optional

    Document | Blob | FormData | string

    The data to be sent to the specified URL (url). For information on valid data inputs, see: MDN Web Docs - XMLHttpRequest.send() Syntax

    requestheaders

    Optional

    Record<string, { key: string; value: string }>

    Allows for the definition of additional header-values for the request header.

    type

    Optional

    string

    The HTTP request method, such as: 'GET', 'POST', 'PUT' and 'DELETE'. By default:

    • If no data is provided with the request, the 'GET' method will be used.
    • If data is provided with the request, the 'POST' method will be used.

    error_scope

    Optional

    object

    Sets the 'this' value of the error callback function.

    success_scope

    Optional

    object

    Sets the 'this' value of the success callback function.

    error

    Optional

    callback function

    The callback function called when an error occurs. The callback function will be passed the following arguments:

    • message: Passed either 'TIMED_OUT' or 'GENERAL'.
    • xhr: Passed the XMLHttpRequest.
    • setting: Passed the XMLHttpRequest settings.

    success

    Optional

    callback function

    The callback function called when the request is successful. The callback function will be passed the following arguments:

Can't find what you're looking for? Let us know.

Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.