<divid=Content><divclass="CClass"><divclass=CTopicid=MainTopic><h1class=CTitle><aname="mxXmlRequest"></a>mxXmlRequest</h1><divclass=CBody><p>XML HTTP request wrapper. See also: <ahref="mxUtils-js.html#mxUtils.get"class=LFunctionid=link29onMouseOver="ShowTip(event, 'tt23', 'link29')"onMouseOut="HideTip('tt23')">mxUtils.get</a>, <ahref="mxUtils-js.html#mxUtils.post"class=LFunctionid=link30onMouseOver="ShowTip(event, 'tt24', 'link30')"onMouseOut="HideTip('tt24')">mxUtils.post</a> and <ahref="mxUtils-js.html#mxUtils.load"class=LFunctionid=link31onMouseOver="ShowTip(event, 'tt25', 'link31')"onMouseOut="HideTip('tt25')">mxUtils.load</a>. This class provides a cross-browser abstraction for Ajax requests.</p><h4class=CHeading>Encoding</h4><p>For encoding parameter values, the built-in encodeURIComponent JavaScript method must be used. For automatic encoding of post data in <ahref="../editor/mxEditor-js.html#mxEditor"class=LClassid=link32onMouseOver="ShowTip(event, 'tt26', 'link32')"onMouseOut="HideTip('tt26')">mxEditor</a> the <ahref="../editor/mxEditor-js.html#mxEditor.escapePostData"class=LVariableid=link33onMouseOver="ShowTip(event, 'tt27', 'link33')"onMouseOut="HideTip('tt27')">mxEditor.escapePostData</a> 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”></p><h4class=CHeading>Example</h4><blockquote><preclass="prettyprint">var onload = function(req)
new mxXmlRequest(url, 'key=value').send(onload, onerror);</pre></blockquote><p>Sends an asynchronous POST request to the specified URL.</p><h4class=CHeading>Example</h4><blockquote><preclass="prettyprint">var req = new mxXmlRequest(url, 'key=value', 'POST', false);
req.send();
mxUtils.alert(req.getDocumentElement());</pre></blockquote><p>Sends a synchronous POST request to the specified URL.</p><h4class=CHeading>Example</h4><blockquote><preclass="prettyprint">var encoder = new mxCodec();
var result = encoder.encode(graph.getModel());
var xml = encodeURIComponent(mxUtils.getXml(result));
new mxXmlRequest(url, 'xml='+xml).send();</pre></blockquote><p>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:</p><blockquote><preclass="prettyprint">string xml = HttpUtility.UrlDecode(context.Request.Params["xml"]);</pre></blockquote><h4class=CHeading>Or in Java as follows</h4><blockquote><preclass="prettyprint">String xml = URLDecoder.decode(request.getParameter("xml"), "UTF-8").replace("\n", "&#xa;");</pre></blockquote><p>Note that the linefeeds should only be replaced if the XML is processed in Java, for example when creating an image.</p><!--START_ND_SUMMARY--><divclass=Summary><divclass=STitle>Summary</div><divclass=SBorder><tableborder=0cellspacing=0cellpadding=0class=STable><trclass="SMain"><tdclass=SEntry><ahref="#mxXmlRequest">mxXmlRequest</a></td><tdclass=SDescription>XML HTTP request wrapper. </td></tr><trclass="SGroup SIndent1"><tdclass=SEntry><ahref="#mxXmlRequest.Functions">Functions</a></td><tdclass=SDescription></td></tr><trclass="SFunction SIndent2 SMarked"><tdclass=SEntry><ahref="#mxXmlRequest.mxXmlRequest"id=link1onMouseOver="ShowTip(event, 'tt1', 'link1')"onMouseOut="HideTip('tt1')">mxXmlRequest</a></td><tdclass=SDescription>Constructs an XML HTTP request.</td></tr><trclass="SGroup SIndent1"><tdclass=SEntry><ahref="#mxXmlRequest.Variables">Variables</a></td><tdclass=SDescription></td></tr><trclass="SVariable SIndent2 SMarked"><tdclass=SEntry><ahref="#mxXmlRequest.url"id=link2onMouseOver="ShowTip(event, 'tt2', 'link2')"onMouseOut="HideTip('tt2')">url</a></td><tdclass=SDescription>Holds the target URL of the request.</td></tr><trclass="SVariable SIndent2"><tdclass=SEntry><ahref="#mxXmlRequest.params"id=link3onMouseOver="ShowTip(event, 'tt3', 'link3')"onMouseOut="HideTip('tt3')">params</a></td><tdclass=SDescription>Holds the form encoded data for the POST request.</td></tr><trclass="SVariable SIndent2 SMarked"><tdclass=SEntry><ahref="#mxXmlRequest.method"id=link4onMouseOver="ShowTip(event, 'tt4', 'link4')"onMouseOut="HideTip('tt4')">method</a></td><tdclass=SDescription>Specifies the request method. </td></tr><trclass="SVariable SIndent2"><tdclass=SEntry><ahref="#mxXmlRequest.async"id=link5onMouseOver="ShowTip(event, 'tt5', 'link5')"onMouseOut="HideTip('tt5')">async</a></td><tdclass=SDescription>Boolean indicating if the request is asynchronous.</td></tr><trclass="SVariable SIndent2 SMarked"><tdclass=SEntry><ahref="#mxXmlRequest.binary"id=link6onMouseOver="ShowTip(event, 'tt6', 'link6')"onMouseOut="HideTip('tt6')">binary</a></td><tdclass=SDescription>Boolean indicating if the request is binary. </td></tr><trclass="SVariable SIndent2"><tdclass=SEntry><ahref="#mxXmlRequest.withCredentials"id=link7onMouseOver="ShowTip(event, 'tt7', 'link7')"onMouseOut="HideTip('tt7')">withCredentials</a></td><tdclass=SDescription>Specifies if withCredentials should be used in HTML5-compliant browsers. </td></tr><trclass="SVariable SIndent2 SMarked"><tdclass=SEntry><ahref="#mxXmlRequest.username"id=link8onMouseOver="ShowTip(event, 'tt8', 'link8')"onMouseOut="HideTip('tt8')">username</a></td><tdclass=SDescription>Specifies the username to be used for authentication.</td></tr><trclass="SVariable SIndent2"><tdclass=SEntry><ahref="#mxXmlRequest.password"id=link9onMouseOver="ShowTip(event, 'tt9', 'link9')"onMouseOut="HideTip('tt9')">password</a></td><tdclass=SDescription>Specifies the password to be used for authentication.</td></tr><trclass="SVariable SIndent2 SMarked"><tdclass=SEntry><ahref="#mxXmlRequest.request"id=link10onMouseOver="ShowTip(event, 'tt10', 'link10')"onMouseOut="HideTip('tt10')">request</a></td><tdclass=SDescription>Holds the inner, browser-specific request object.</td></tr><trclass="SVariable SIndent2"><tdclass=SEntry><ahref="#mxXmlRequest.decodeSimulateValues"id=link11onMouseOver="ShowTip(event, 'tt11', 'link11')"onMouseOut="HideTip('tt11')">decodeSimulateValues<
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.mxXmlRequest"></a>mxXmlRequest</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><td><tableborder=0cellspacing=0cellpadding=0><tr><tdclass="PBeforeParameters prettyprint "nowrap>function mxXmlRequest(</td><tdclass="PParameter prettyprint "nowrap>url,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>params,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>method,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>async,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>username,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>password</td><tdclass="PAfterParameters prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Constructs an XML HTTP request.</p><h4class=CHeading>Parameters</h4><tableborder=0cellspacing=0cellpadding=0class=CDescriptionList><tr><tdclass=CDLEntry>url</td><tdclass=CDLDescription>Target URL of the request.</td></tr><tr><tdclass=CDLEntry>params</td><tdclass=CDLDescription>Form encoded parameters to send with a POST request.</td></tr><tr><tdclass=CDLEntry>method</td><tdclass=CDLDescription>String that specifies the request method. Possible values are POST and GET. Default is POST.</td></tr><tr><tdclass=CDLEntry>async</td><tdclass=CDLDescription>Boolean specifying if an asynchronous request should be used. Default is true.</td></tr><tr><tdclass=CDLEntry>username</td><tdclass=CDLDescription>String specifying the username to be used for the request.</td></tr><tr><tdclass=CDLEntry>password</td><tdclass=CDLDescription>String specifying the password to be used for the request.</td></tr></table></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.url"></a>url</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.url</td></tr></table></blockquote><p>Holds the target URL of the request.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.params"></a>params</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.params</td></tr></table></blockquote><p>Holds the form encoded data for the POST request.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.method"></a>method</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.method</td></tr></table></blockquote><p>Specifies the request method. Possible values are POST and GET. Default is POST.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.async"></a>async</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.async</td></tr></table></blockquote><p>Boolean indicating if the request is asynchronous.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.binary"></a>binary</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.binary</td></tr></table></blockquote><p>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.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.withCredentials"></a>withCredentials</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.withCredentials</td></tr></table></blockquote><p>Specifies if withCredentials should be used in HTML5-compliant browsers. Default is false.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.username"></a>username</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.username</td></tr></table></blockquote><p>Specifies the username to be used for authentication.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.password"></a>password</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.password</td></tr></table></blockquote><p>Specifies the password to be used for authentication.</p></div></div></div>
<divclass="CVariable"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.decodeSimulateValues"></a>decodeSimulateValues</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.decodeSimulateValues</td></tr></table></blockquote><p>Specifies if request values should be decoded as URIs before setting the textarea value in <ahref="#mxXmlRequest.simulate"class=LFunctionid=link34onMouseOver="ShowTip(event, 'tt12', 'link34')"onMouseOut="HideTip('tt12')">simulate</a>. Defaults to false for backwards compatibility, to avoid another decode on the server this should be set to true.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.getText"></a>getText</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.getText = function()</td></tr></table></blockquote><p>Returns the response as a string.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.isReady"></a>isReady</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.isReady = function()</td></tr></table></blockquote><p>Returns true if the response is ready.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.getDocumentElement"></a>getDocumentElement</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.getDocumentElement = function()</td></tr></table></blockquote><p>Returns the document element of the response XML document.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.getXml"></a>getXml</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.getXml = function()</td></tr></table></blockquote><p>Returns the response as an XML document. Use <ahref="#mxXmlRequest.getDocumentElement"class=LFunctionid=link37onMouseOver="ShowTip(event, 'tt17', 'link37')"onMouseOut="HideTip('tt17')">getDocumentElement</a> to get the document element of the XML document.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.getText"></a>getText</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.getText = function()</td></tr></table></blockquote><p>Returns the response as a string.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.getStatus"></a>getStatus</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.getStatus = function()</td></tr></table></blockquote><p>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.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.send"></a>send</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><td><tableborder=0cellspacing=0cellpadding=0><tr><tdclass="PBeforeParameters prettyprint "nowrap>mxXmlRequest.prototype.send = function(</td><tdclass="PParameter prettyprint "nowrap>onload,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>onerror,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>timeout,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>ontimeout</td><tdclass="PAfterParameters prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Send the <ahref="#mxXmlRequest.request"class=LVariableid=link39onMouseOver="ShowTip(event, 'tt10', 'link39')"onMouseOut="HideTip('tt10')">request</a> to the target URL using the specified functions to process the response asychronously.</p><h4class=CHeading>Parameters</h4><tableborder=0cellspacing=0cellpadding=0class=CDescriptionList><tr><tdclass=CDLEntry>onload</td><tdclass=CDLDescription>Function to be invoked if a successful response was received.</td></tr><tr><tdclass=CDLEntry>onerror</td><tdclass=CDLDescription>Function to be called on any error.</td></tr><tr><tdclass=CDLEntry>timeout</td><tdclass=CDLDescription>Optional timeout in ms before calling ontimeout.</td></tr><tr><tdclass=CDLEntry>ontimeout</td><tdclass=CDLDescription>Optional function to execute on timeout.</td></tr></table></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.setRequestHeaders"></a>setRequestHeaders</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><td><tableborder=0cellspacing=0cellpadding=0><tr><tdclass="PBeforeParameters prettyprint "nowrap>mxXmlRequest.prototype.setRequestHeaders = function(</td><tdclass="PParameter prettyprint "nowrap>request,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>params</td><tdclass="PAfterParameters prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Sets the headers for the given request and parameters. This sets the content-type to application/x-www-form-urlencoded if any params exist.</p><h4class=CHeading>Example</h4><blockquote><preclass="prettyprint">request.setRequestHeaders = function(request, params)
};</pre></blockquote><p>Use the code above before calling <ahref="#mxXmlRequest.send"class=LFunctionid=link40onMouseOver="ShowTip(event, 'tt21', 'link40')"onMouseOut="HideTip('tt21')">send</a> if you require a multipart/form-data request.</p></div></div></div>
<divclass="CFunction"><divclass=CTopic><h3class=CTitle><aname="mxXmlRequest.simulate"></a>simulate</h3><divclass=CBody><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><td><tableborder=0cellspacing=0cellpadding=0><tr><tdclass="PBeforeParameters prettyprint "nowrap>mxXmlRequest.prototype.simulate = function(</td><tdclass="PParameter prettyprint "nowrap>doc,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>target</td><tdclass="PAfterParameters prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Creates and posts a request to the given target URL using a dynamically created form inside the given document.</p><h4class=CHeading>Parameters</h4><tableborder=0cellspacing=0cellpadding=0class=CDescriptionList><tr><tdclass=CDLEntry>docs</td><tdclass=CDLDescription>Document that contains the form element.</td></tr><tr><tdclass=CDLEntry>target</td><tdclass=CDLDescription>Target to send the form result to.</td></tr></table></div></div></div>
<divclass=CToolTipid="tt1"><divclass=CFunction><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><td><tableborder=0cellspacing=0cellpadding=0><tr><tdclass="PBeforeParameters prettyprint "nowrap>function mxXmlRequest(</td><tdclass="PParameter prettyprint "nowrap>url,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>params,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>method,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>async,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>username,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>password</td><tdclass="PAfterParameters prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Constructs an XML HTTP request.</div></div><divclass=CToolTipid="tt2"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.url</td></tr></table></blockquote>Holds the target URL of the request.</div></div><divclass=CToolTipid="tt3"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.params</td></tr></table></blockquote>Holds the form encoded data for the POST request.</div></div><divclass=CToolTipid="tt4"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.method</td></tr></table></blockquote>Specifies the request method. </div></div><divclass=CToolTipid="tt5"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.async</td></tr></table></blockquote>Boolean indicating if the request is asynchronous.</div></div><divclass=CToolTipid="tt6"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.binary</td></tr></table></blockquote>Boolean indicating if the request is binary. </div></div><divclass=CToolTipid="tt7"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.withCredentials</td></tr></table></blockquote>Specifies if withCredentials should be used in HTML5-compliant browsers. </div></div><divclass=CToolTipid="tt8"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.username</td></tr></table></blockquote>Specifies the username to be used for authentication.</div></div><divclass=CToolTipid="tt9"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.password</td></tr></table></blockquote>Specifies the password to be used for authentication.</div></div><divclass=CToolTipid="tt10"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.request</td></tr></table></blockquote>Holds the inner, browser-specific request object.</div></div><divclass=CToolTipid="tt11"><divclass=CVariable><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><tdclass="prettyprint">mxXmlRequest.prototype.decodeSimulateValues</td></tr></table></blockquote>Specifies if request values should be decoded as URIs before setting the textarea value in simulate. </div></div><divclass=CToolTipid="tt12"><divclass=CFunction><blockquote><tableborder=0cellspacing=0cellpadding=0class="Prototype"><tr><td><tableborder=0cellspacing=0cellpadding=0><tr><tdclass="PBeforeParameters prettyprint "nowrap>mxXmlRequest.prototype.simulate = function(</td><tdclass="PParameter prettyprint "nowrap>doc,</td></tr><tr><td></td><tdclass="PParameter prettyprint "nowrap>target</td><tdclass="PAfterParameters prettyprint "nowrap>)</td></tr><