mxXmlRequest

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.  <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8”>

Example

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

var onerror = function(req)
{
  mxUtils.alert(req.getStatus());
}
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:

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

Or in Java as follows

String xml = URLDecoder.decode(request.getParameter("xml"), "UTF-8").replace("\n", "&#xa;");

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

Summary
mxXmlRequestXML HTTP request wrapper.
Functions
mxXmlRequestConstructs an XML HTTP request.
Variables
urlHolds the target URL of the request.
paramsHolds the form encoded data for the POST request.
methodSpecifies the request method.
asyncBoolean indicating if the request is asynchronous.
binaryBoolean indicating if the request is binary.
withCredentialsSpecifies if withCredentials should be used in HTML5-compliant browsers.
usernameSpecifies the username to be used for authentication.
passwordSpecifies the password to be used for authentication.
requestHolds the inner, browser-specific request object.
decodeSimulateValuesSpecifies if request values should be decoded as URIs before setting the textarea value in simulate.
Functions
isBinaryReturns binary.
setBinarySets binary.
getTextReturns the response as a string.
isReadyReturns true if the response is ready.
getDocumentElementReturns the document element of the response XML document.
getXmlReturns the response as an XML document.
getTextReturns the response as a string.
getStatusReturns the status as a number, eg.
createCreates and returns the inner request object.
sendSend the request to the target URL using the specified functions to process the response asychronously.
setRequestHeadersSets the headers for the given request and parameters.
simulateCreates and posts a request to the given target URL using a dynamically created form inside the given document.

Functions

mxXmlRequest

function mxXmlRequest(url,
params,
method,
async,
username,
password)

Constructs an XML HTTP request.

Parameters

urlTarget URL of the request.
paramsForm encoded parameters to send with a POST request.
methodString that specifies the request method.  Possible values are POST and GET.  Default is POST.
asyncBoolean specifying if an asynchronous request should be used.  Default is true.
usernameString specifying the username to be used for the request.
passwordString specifying the password to be used for the request.

Variables

url

mxXmlRequest.prototype.url

Holds the target URL of the request.

params

mxXmlRequest.prototype.params

Holds the form encoded data for the POST request.

method

mxXmlRequest.prototype.method

Specifies the request method.  Possible values are POST and GET.  Default is POST.

async

mxXmlRequest.prototype.async

Boolean indicating if the request is asynchronous.

binary

mxXmlRequest.prototype.binary

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.

withCredentials

mxXmlRequest.prototype.withCredentials

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

username

mxXmlRequest.prototype.username

Specifies the username to be used for authentication.

password

mxXmlRequest.prototype.password

Specifies the password to be used for authentication.

request

mxXmlRequest.prototype.request

Holds the inner, browser-specific request object.

decodeSimulateValues

mxXmlRequest.prototype.decodeSimulateValues

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.

Functions

isBinary

mxXmlRequest.prototype.isBinary = function()

Returns binary.

setBinary

mxXmlRequest.prototype.setBinary = function(value)

Sets binary.

getText

mxXmlRequest.prototype.getText = function()

Returns the response as a string.

isReady

mxXmlRequest.prototype.isReady = function()

Returns true if the response is ready.

getDocumentElement

mxXmlRequest.prototype.getDocumentElement = function()

Returns the document element of the response XML document.

getXml

mxXmlRequest.prototype.getXml = function()

Returns the response as an XML document.  Use getDocumentElement to get the document element of the XML document.

getText

mxXmlRequest.prototype.getText = function()

Returns the response as a string.

getStatus

mxXmlRequest.prototype.getStatus = function()

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.

create

mxXmlRequest.prototype.create = function()

Creates and returns the inner request object.

send

mxXmlRequest.prototype.send = function(onload,
onerror,
timeout,
ontimeout)

Send the request to the target URL using the specified functions to process the response asychronously.

Parameters

onloadFunction to be invoked if a successful response was received.
onerrorFunction to be called on any error.
timeoutOptional timeout in ms before calling ontimeout.
ontimeoutOptional function to execute on timeout.

setRequestHeaders

mxXmlRequest.prototype.setRequestHeaders = function(request,
params)

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.

simulate

mxXmlRequest.prototype.simulate = function(doc,
target)

Creates and posts a request to the given target URL using a dynamically created form inside the given document.

Parameters

docsDocument that contains the form element.
targetTarget to send the form result to.
function mxXmlRequest(url,
params,
method,
async,
username,
password)
Constructs an XML HTTP request.
mxXmlRequest.prototype.url
Holds the target URL of the request.
mxXmlRequest.prototype.params
Holds the form encoded data for the POST request.
mxXmlRequest.prototype.method
Specifies the request method.
mxXmlRequest.prototype.async
Boolean indicating if the request is asynchronous.
mxXmlRequest.prototype.binary
Boolean indicating if the request is binary.
mxXmlRequest.prototype.withCredentials
Specifies if withCredentials should be used in HTML5-compliant browsers.
mxXmlRequest.prototype.username
Specifies the username to be used for authentication.
mxXmlRequest.prototype.password
Specifies the password to be used for authentication.
mxXmlRequest.prototype.request
Holds the inner, browser-specific request object.
mxXmlRequest.prototype.decodeSimulateValues
Specifies if request values should be decoded as URIs before setting the textarea value in simulate.
mxXmlRequest.prototype.simulate = function(doc,
target)
Creates and posts a request to the given target URL using a dynamically created form inside the given document.
mxXmlRequest.prototype.isBinary = function()
Returns binary.
mxXmlRequest.prototype.setBinary = function(value)
Sets binary.
mxXmlRequest.prototype.getText = function()
Returns the response as a string.
mxXmlRequest.prototype.isReady = function()
Returns true if the response is ready.
mxXmlRequest.prototype.getDocumentElement = function()
Returns the document element of the response XML document.
mxXmlRequest.prototype.getXml = function()
Returns the response as an XML document.
mxXmlRequest.prototype.getStatus = function()
Returns the status as a number, eg.
mxXmlRequest.prototype.create = function()
Creates and returns the inner request object.
mxXmlRequest.prototype.send = function(onload,
onerror,
timeout,
ontimeout)
Send the request to the target URL using the specified functions to process the response asychronously.
mxXmlRequest.prototype.setRequestHeaders = function(request,
params)
Sets the headers for the given request and parameters.
get: function(url,
onload,
onerror,
binary,
timeout,
ontimeout)
Loads the specified URL asynchronously and invokes the given functions depending on the request status.
post: function(url,
params,
onload,
onerror)
Posts the specified params to the given URL asynchronously and invokes the given functions depending on the request status.
load: function(url)
Loads the specified URL synchronously and returns the mxXmlRequest.
Extends mxEventSource to implement a application wrapper for a graph that adds actions, I/O using mxCodec, auto-layout using mxLayoutManager, command history using undoManager, and standard dialogs and widgets, eg.
mxEditor.prototype.escapePostData
Specifies if the data in the post request for saving a diagram should be converted using encodeURIComponent.
Close