1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3 * text of the license. */
5 OpenLayers.ProxyHost = "/proxy/?url=";
\r
6 //OpenLayers.ProxyHost = "examples/proxy.cgi?url=";
\r
9 * Ajax reader for OpenLayers
\r
11 *@uri url to do remote XML http get
\r
12 *@param 'get' format params (x=y&a=b...)
\r
13 *@who object to handle callbacks for this request
\r
14 *@complete the function to be called on success
\r
15 *@failure the function to be called on failure
\r
17 * example usage from a caller:
\r
19 * caps: function(request) {
\r
23 * OpenLayers.loadURL(url,params,this,caps);
\r
25 * Notice the above example does not provide an error handler; a default empty
\r
26 * handler is provided which merely logs the error if a failure handler is not
\r
35 OpenLayers.nullHandler = function(request) {
\r
36 alert("Unhandled request return " + request.statusText);
\r
39 /** Background load a document
\r
41 * @param {String} uri URI of source doc
\r
42 * @param {String} params Params on get (doesnt seem to work)
\r
43 * @param {Object} caller object which gets callbacks
\r
44 * @param {Function} onComplete callback for success
\r
45 * @param {Function} onFailure callback for failure
\r
47 * Both callbacks optional (though silly)
\r
49 OpenLayers.loadURL = function(uri, params, caller,
\r
50 onComplete, onFailure) {
\r
52 if (OpenLayers.ProxyHost && uri.startsWith("http")) {
\r
53 uri = OpenLayers.ProxyHost + escape(uri);
\r
58 params += "&cachehack=" + new Date().getTime();
\r
61 var success = (onComplete) ? onComplete.bind(caller)
\r
62 : OpenLayers.nullHandler;
\r
64 var failure = (onFailure) ? onFailure.bind(caller)
\r
65 : OpenLayers.nullHandler;
\r
67 // from prototype.js
\r
68 new Ajax.Request(uri,
\r
71 onComplete: success,
\r
77 /** Parse XML into a doc structure
\r
78 * @param {String} text
\r
80 * @returns Parsed Ajax Response ??
\r
83 OpenLayers.parseXMLString = function(text) {
\r
85 //MS sucks, if the server is bad it dies
\r
86 var index = text.indexOf('<');
\r
88 text = text.substring(index);
\r
91 var ajaxResponse = Try.these(
\r
93 var xmldom = new ActiveXObject('Microsoft.XMLDOM');
\r
94 xmldom.loadXML(text);
\r
98 return new DOMParser().parseFromString(text, 'text/xml');
\r
101 var req = new XMLHttpRequest();
\r
102 req.open("GET", "data:" + "text/xml" +
\r
103 ";charset=utf-8," + encodeURIComponent(text), false);
\r
104 if (req.overrideMimeType) {
\r
105 req.overrideMimeType("text/xml");
\r
108 return req.responseXML;
\r
112 return ajaxResponse;
\r