Example: Use the xhr object and the Ajax object of ext2.0 to send a request to an ArcIMS server and return the result.
VaR Axl = '<? XML version = "1.0" encoding = "UTF-8"?> /N <ArcXML version = "1.1">/n <request>/n <get_service_info Renderer = "false" extensions = "false" fields = "false"/>/n </ request>/n </ArcXML>/N ';
VaR url = 'HTTP: // www. studioat. it/servlet/COM. ESRI. esrimap. esrimap? Servicename = comunegarzeno & form = false & clientversion = 4.0 ';
// Xhr example
VaR HTTP;
Ext. Get ('okbutton2'). On ('click', function (){
HTTP = gethttpobject ();
If (HTTP! = NULL )){
HTTP. Open ("Post", URLs, true );
HTTP. onreadystatechange = parselayers; // The IMS service information will be parsed by parselayers
HTTP. setRequestHeader ('content-type', 'application/X-WWW-form-urlencoded ');
HTTP. Send (Axl );
}
});
Function parselayers (){
If (HTTP. readystate = 4 ){
If (HTTP. Status = 200 ){
VaR result = http. responsetext;
Alert (result); // everything is normal
} Else alert ("error retreiving data ");
}
}
Function gethttpobject (){
VaR XMLHTTP;
// Mozilla Firefox
If (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
// IE
} Else if (window. activexobject ){
VaR aversions = ['msxml2. xmlhttp.5.0 ', 'msxml2. xmlhttp.4.0', 'msxml2. xmlhttp.3.0 ', 'msxml2. xmlhttp', 'Microsoft. xmlhttp'];
For (VAR I = 0; I <aversions. length; I ++ ){
Try {
XMLHTTP = new activexobject (aversions [I]);
} Catch (e ){}
}
}
Return XMLHTTP;
}
But the Ajax method of ext2.0 is used:
Ext. Get ('okclick'). On ('click', function (){
Ext. Ajax. Request ({
URL: URLs,
Headers: {'content-type': 'text/xml '},
Params: Axl,
Method: 'post ',
// Xmldata: Axl, or
Success: function (result, request ){
Alert (result. responsetext );
},
Failure: function (result, request ){
Ext. MessageBox. Alert ('failed', 'successfully posted form :');
}
});
});