TinyMCE:API/tinymce.util.XHR/send

From Moxiecode Documentation Wiki

Jump to: navigation, search

Contents

Method: send

Summary

Sends a XMLHTTPRequest. Consult the Wiki for details on what settings this method takes.

Syntax

<void> send(<Object> o)

Parameters

o
Object will target URL, callbacks and other info needed to make the request.
Possible properties of o:
async
Boolean, default true; defines whether the XHR call will be synchronous (false, browser waits for the result of the call) or asynchronous (true, the call is made and the control is returned to user)
content_type
String; defines the MIME type of the request/response, e.g. "text/plain", "text/html", "text/json", ...
data
String; list of parameters to be sent to server
error
Function; callback function to be executed if the XHR call ends in error
error: function( String type=["TIMED_OUT" | "GENERAL"], XmlHttpRequest request, Object o )
error_scope
Object; a scope for executing error callback function
scope
Object; a scope for executing success and error callback functions
success
Function; callback function to be executed on the successful completion of XHR request
success: function( String response, XmlHttpRequest request, Object o )
success_scope
Object; a scope for executing success function
type
String; type of an HTTP request ("POST", "GET", "HEAD", ...)
url
String; the URL to which a request is sent

Example

   var myObjectInstance = new MyObject();
   myObjectInstance.someProperty = "Some Text";
   
   tinymce.util.XHR.send({
       url : "service.php",
       content_type : "text/html",
       type : "POST",
       data : tinymce.util.JSON.serialize({
           param1 : "Text 1",
           param2 : 150,
           param3 : false
       }),
       async : false,
       scope : myObjectInstance,
       
       success : function( data, req, o ) {
           var div = document.createElement("div");
           div.innerHTML = data;
           alert( this.someProperty ); // Should display "Some Text"
       },
       
       error : function( type, req, o ){
           alert( type ); // Should display "TIMED_OUT" or "GENERAL"
           alert( req.status ); // Should display anything but 200
           alert( o.url ); // Should display "service.php"
       }
   });

Personal tools