XML HTTP request wrapper. See also: mxUtils.get, mxUtils.post and mxUtils.load. This class provides a cross-browser abstraction for Ajax requests.
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”>
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.
var req = new mxXmlRequest(url, 'key=value', 'POST', false); req.send(); mxUtils.alert(req.getDocumentElement());
Sends a synchronous POST request to the specified URL.
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"]);
String xml = URLDecoder.decode(request.getParameter("xml"), "UTF-8").replace("\n", "
");
Note that the linefeeds should only be replaced if the XML is processed in Java, for example when creating an image.
mxXmlRequest | XML HTTP request wrapper. |
Functions | |
mxXmlRequest | Constructs an XML HTTP request. |
Variables | |
url | Holds the target URL of the request. |
params | Holds the form encoded data for the POST request. |
method | Specifies the request method. |
async | Boolean indicating if the request is asynchronous. |
binary | Boolean indicating if the request is binary. |
withCredentials | Specifies if withCredentials should be used in HTML5-compliant browsers. |
username | Specifies the username to be used for authentication. |
password | Specifies the password to be used for authentication. |
request | Holds the inner, browser-specific request object. |
decodeSimulateValues | Specifies if request values should be decoded as URIs before setting the textarea value in simulate. |
Functions | |
isBinary | Returns binary. |
setBinary | Sets binary. |
getText | Returns the response as a string. |
isReady | Returns true if the response is ready. |
getDocumentElement | Returns the document element of the response XML document. |
getXml | Returns the response as an XML document. |
getStatus | Returns the status as a number, eg. |
create | Creates and returns the inner request object. |
send | Send the request to the target URL using the specified functions to process the response asychronously. |
setRequestHeaders | Sets the headers for the given request and parameters. |
simulate | Creates and posts a request to the given target URL using a dynamically created form inside the given document. |
function mxXmlRequest( url, params, method, async, username, password )
Constructs an XML HTTP request.
url | Target URL of the request. |
params | Form encoded parameters to send with a POST request. |
method | String that specifies the request method. Possible values are POST and GET. Default is POST. |
async | Boolean specifying if an asynchronous request should be used. Default is true. |
username | String specifying the username to be used for the request. |
password | String specifying the password to be used for the request. |
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.
mxXmlRequest.prototype.isBinary = function()
Returns binary.
mxXmlRequest.prototype.setBinary = function( value )
Sets binary.
mxXmlRequest.prototype.getXml = function()
Returns the response as an XML document. Use getDocumentElement to get the document element of the XML document.
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.
Note: Due to technical limitations, onerror is currently ignored.
onload | Function to be invoked if a successful response was received. |
onerror | Function to be called on any error. Unused in this implementation, intended for overriden function. |
timeout | Optional timeout in ms before calling ontimeout. |
ontimeout | Optional function to execute on timeout. |
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.
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.
Constructs an XML HTTP request.
function mxXmlRequest( url, params, method, async, username, password )
Holds the target URL of the request.
mxXmlRequest.prototype.url
Holds the form encoded data for the POST request.
mxXmlRequest.prototype.params
Specifies the request method.
mxXmlRequest.prototype.method
Boolean indicating if the request is asynchronous.
mxXmlRequest.prototype.async
Boolean indicating if the request is binary.
mxXmlRequest.prototype.binary
Specifies if withCredentials should be used in HTML5-compliant browsers.
mxXmlRequest.prototype.withCredentials
Specifies the username to be used for authentication.
mxXmlRequest.prototype.username
Specifies the password to be used for authentication.
mxXmlRequest.prototype.password
Holds the inner, browser-specific request object.
mxXmlRequest.prototype.request
Specifies if request values should be decoded as URIs before setting the textarea value in simulate.
mxXmlRequest.prototype.decodeSimulateValues
Creates and posts a request to the given target URL using a dynamically created form inside the given document.
mxXmlRequest.prototype.simulate = function( doc, target )
Returns binary.
mxXmlRequest.prototype.isBinary = function()
Sets binary.
mxXmlRequest.prototype.setBinary = function( value )
Returns the response as a string.
mxXmlRequest.prototype.getText = function()
Returns true if the response is ready.
mxXmlRequest.prototype.isReady = function()
Returns the document element of the response XML document.
mxXmlRequest.prototype.getDocumentElement = function()
Returns the response as an XML document.
mxXmlRequest.prototype.getXml = function()
Returns the status as a number, eg.
mxXmlRequest.prototype.getStatus = function()
Creates and returns the inner request object.
mxXmlRequest.prototype.create = function()
Send the request to the target URL using the specified functions to process the response asychronously.
mxXmlRequest.prototype.send = function( onload, onerror, timeout, ontimeout )
Sets the headers for the given request and parameters.
mxXmlRequest.prototype.setRequestHeaders = function( request, params )
Loads the specified URL asynchronously and invokes the given functions depending on the request status.
get: function( url, onload, onerror, binary, timeout, ontimeout, headers )
Posts the specified params to the given URL asynchronously and invokes the given functions depending on the request status.
post: function( url, params, onload, onerror )
Loads the specified URL synchronously and returns the mxXmlRequest.
load: function( url )
Specifies if the data in the post request for saving a diagram should be converted using encodeURIComponent.
mxEditor.prototype.escapePostData