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');
});
Summary
Methods
Name | Summary | Defined by |
---|---|---|
Fires the specified event by name. Consult the event reference for more details on each event. |
||
Returns true/false if the object has a event of the specified name. |
||
Unbinds an event listener to a specific event by name. Consult the event reference for more details on each event. |
||
Binds an event listener to a specific event by name. Consult the event reference for more details on each event. |
||
Bind the event callback and once it fires the callback is removed. Consult the event reference for more details on each event. |
||
Sends a XMLHTTPRequest. |
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.
hasEventListeners()
hasEventListeners(name: String): Boolean
Returns true/false if the object has a event of the specified name.
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.
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.
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.
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.
<div> <table> <thead> <tr style="text-align: center;"> <th>Setting</th> <th>Required/
Optional</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td> <p>`url`</p> </td> <td>Required</td> <td> <p>`string`</p> </td> <td>Address to send the request to, such as the back-end server.</td> </tr> <tr> <td> <p><code>async
</code></p>
</td>
<td>Optional</td>
<td>
<p>`boolean`</p>
</td>
<td>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.</td>
</tr>
<tr>
<td>
<p><code>content_type
</code></p> </td> <td>Optional</td> <td> <p>`string`</p> </td> <td>Used to define the mime-type of the data. Similar to <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/overrideMimeType"> the XMLHttpRequest.overrideMimeType method</a>.</td> </tr> <tr> <td> <p><code>crossDomain
</code></p>
</td>
<td>Optional</td>
<td>
<p>`boolean`</p>
</td>
<td>When true
, the withCredentials property will be set to true
.
For information on the withCredentials property, see:
<a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials">
MDN Web Docs - XMLHttpRequest.withCredentials</a>.</td>
</tr>
<tr>
<td>
<p><code>data
</code></p>
</td>
<td>Optional</td>
<td>
<p>`Document | Blob | FormData | string`</p>
</td>
<td>The data to be sent to the specified URL (url
). For information on valid data inputs,
see: <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#Syntax">
MDN Web Docs - XMLHttpRequest.send() Syntax</a></td>
</tr>
<tr>
<td>
<p>`requestheaders`</p>
</td>
<td>Optional</td>
<td>
<p>`Record<string, { key: string; value: string }>`</p>
</td>
<td>Allows for the definition of additional
<a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader">
header-values for the request header</a>.</td>
</tr>
<tr>
<td>
<p>`type`</p>
</td>
<td>Optional</td>
<td>
<p>`string`</p>
</td>
<td>
<p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods">HTTP request method</a>,
such as: 'GET'
, 'POST'
, 'PUT'
and 'DELETE'
.
By default:</p>
<ul>
<li>If no data is provided with the request, the 'GET'
method will be used.</li>
<li>If data is provided with the request, the 'POST'
method will be used.</li>
</ul>
</td>
</tr>
<tr>
<td>
<p>`error_scope`</p>
</td>
<td>Optional</td>
<td>
<p>`object`</p>
</td>
<td>Sets the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this">
‘this’</a> value of the error callback function.</td>
</tr>
<tr>
<td>
<p><code>success_scope
</code></p> </td> <td>Optional</td> <td> <p>`object`</p> </td> <td>Sets the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this"> ‘this’</a> value of the success callback function.</td> </tr> <tr> <td> <p><code>error
</code></p>
</td>
<td>Optional</td>
<td>
<p>`callback function`</p>
</td>
<td>
<p>The callback function called when an error occurs.
The callback function will be passed the following arguments:</p>
<ul>
<li>`message`: Passed either 'TIMED_OUT'
or 'GENERAL'
.</li>
<li>`xhr`: Passed the XMLHttpRequest.</li>
<li>`setting`: Passed the XMLHttpRequest settings.</li>
</ul>
</td>
</tr>
<tr>
<td>
<p>`success`</p>
</td>
<td>Optional</td>
<td>
<p>`callback function`</p>
</td>
<td>
<p>The callback function called when the request is successful.
The callback function will be passed the following arguments:</p>
<ul>
<li>`text`: The text response from the server.
For information on the response text, see:
<a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText">
MDN Web Docs - XMLHttpRequest.responseText</a>.</li>
<li>`xhr`: Passed the XMLHttpRequest.</li>
<li>`setting`: Passed the XMLHttpRequest settings.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>