Options
All
  • Public
  • Public/Protected
  • All
Menu

XML HTTP request wrapper. See also: mxUtils.get, mxUtils.post and mxUtils.load. This class provides a cross-browser abstraction for Ajax requests.

Encoding:

For encoding parameter values, the built-in encodeURIComponent JavaScript method must be used. For automatic encoding of post data in mxEditor the mxEditor.escapePostData switch can be set to true (default). The encoding will be carried out using the conte type of the page. That is, the page containting the editor should contain a meta tag in the header, eg.

example
var onload = function(req)
{
  mxUtils.alert(req.getDocumentElement());
}

var onerror = function(req)
{
  mxUtils.alert('Error');
}
new mxXmlRequest(url, 'key=value').send(onload, onerror);

Sends an asynchronous POST request to the specified URL.

example
var req = new mxXmlRequest(url, 'key=value', 'POST', false);
req.send();
mxUtils.alert(req.getDocumentElement());

Sends a synchronous POST request to the specified URL.

example
var encoder = new mxCodec();
var result = encoder.encode(graph.getModel());
var xml = encodeURIComponent(mxUtils.getXml(result));
new mxXmlRequest(url, 'xml='+xml).send();

Sends an encoded graph model to the specified URL using xml as the parameter name. The parameter can then be retrieved in C# as follows:

(code) string xml = HttpUtility.UrlDecode(context.Request.Params["xml"]); (end)

Or in Java as follows:

(code) String xml = URLDecoder.decode(request.getParameter("xml"), "UTF-8").replace("\n", " "); (end)

Note that the linefeeds should only be replaced if the XML is processed in Java, for example when creating an image.

Hierarchy

  • mxXmlRequest

Index

Constructors

constructor

  • new mxXmlRequest(url: string, params: any, method: "POST" | "GET", async: boolean, username: string, password: string): mxXmlRequest
  • Constructs an XML HTTP request.

    default

    'POST'

    default

    true

    Parameters

    • url: string

      Target URL of the request.

    • params: any

      Form encoded parameters to send with a POST request.

    • method: "POST" | "GET"

      String that specifies the request method. Possible values are POST and GET. Default is POST.

    • async: boolean

      Boolean specifying if an asynchronous request should be used. Default is true.

    • username: string

      String specifying the username to be used for the request.

    • password: string

      String specifying the password to be used for the request.

    Returns mxXmlRequest

Properties

binary

binary: boolean

Boolean indicating if the request is binary. This option is ignored in IE. In all other browsers the requested mime type is set to text/plain; charset=x-user-defined. Default is false.

default

false

decodeSimulateValues

decodeSimulateValues: boolean

Specifies if request values should be decoded as URIs before setting the textarea value in simulate. Defaults to false for backwards compatibility, to avoid another decode on the server this should be set to true.

request

request: any

Holds the inner, browser-specific request object.

withCredentials

withCredentials: boolean

Specifies if withCredentials should be used in HTML5-compliant browsers. Default is false.

default

false

Methods

create

  • create(): any

getDocumentElement

  • getDocumentElement(): XMLDocument

getStatus

  • getStatus(): number
  • Returns the status as a number, eg. 404 for "Not found" or 200 for "OK". Note: The NS_ERROR_NOT_AVAILABLE for invalid responses cannot be cought.

    Returns number

getText

  • getText(): string

getXml

  • getXml(): XMLDocument

isBinary

  • isBinary(): boolean

isReady

  • isReady(): boolean

send

  • send(onload: Function, onerror: Function, timeout?: number, ontimeout?: Function): void
  • Send the to the target URL using the specified functions to process the response asychronously.

    Note: Due to technical limitations, onerror is currently ignored.

    Parameters

    • onload: Function

      Function to be invoked if a successful response was received.

    • onerror: Function

      Function to be called on any error. Unused in this implementation, intended for overriden function.

    • Optional timeout: number

      Optional timeout in ms before calling ontimeout.

    • Optional ontimeout: Function

      Optional function to execute on timeout.

    Returns void

setBinary

  • setBinary(value: boolean): void

setRequestHeaders

  • setRequestHeaders(request: any, params: any): void
  • Sets the headers for the given request and parameters. This sets the content-type to application/x-www-form-urlencoded if any params exist.

    example
    request.setRequestHeaders = function(request, params)
    {
      if (params != null)
      {
        request.setRequestHeader('Content-Type',
                'multipart/form-data');
        request.setRequestHeader('Content-Length',
                params.length);
      }
    };
    

    Use the code above before calling send if you require a multipart/form-data request.

    Parameters

    • request: any
    • params: any

    Returns void

simulate

  • simulate(doc: any, target: any): void
  • Creates and posts a request to the given target URL using a dynamically created form inside the given document.

    Parameters

    • doc: any

      Document that contains the form element.

    • target: any

      Target to send the form result to.

    Returns void

Generated using TypeDoc