GetURL
From Svg wiki
The function getURL() is a JavaScript function commonly used in SVG scripts to fetch another file. It allows scripts to download data without having to reload the SVG document. As simple as this concept may sound, it is very powerful. Using getURL it is possible for SVG graphics to be dynamically updated with remote data as a result of user interactions or timed data feeds.
Example uses for getURL include a map that gets more detailed the more the image is zoomed (where file sizes would get too large -- and image rendering too slow -- if all the data were sent immediately), a set of gauges that monitor remote machines (where the data is updated in real time, and is unavailable at time of initial load), or a chart that plots out data according to user input (where calculations might be proprietary, security-sensitive, or too complex to do with client-side scripting).
Important note: getURL() is a non-standard extension introduced in Adobe's SVG Viewer. There are other methods to do the same thing in other SVG implementations.
The syntax is as follows:
getURL(url, callback);
| url | A string containing the URL of the file that is to be fetched. For security reasons the file must be from the same domain as the SVG document. |
| callback | Either a function or an object with a method called 'operationComplete'. Once getURL has finished downloading the file it will invoke the function/operationComplete and pass it an object. The object can be used by the function/operationComplete to get the contents of the file. The object has three properties: the property 'success' is a boolean value, and seems to be useless since it always has the value true; the property 'contentType' is a string set to the MIME type the server claimed for the file; and finally the property 'content' is a string containing everything in the file.
|
Links
---
Using XMLHttpRequest to provide getURL in Firefox
adapted from code posted at http://www.jibbering.com/2002/5/dynamic-update-svg.html
/**
* httpRequest
* factory used for creating XMLHttpRequest objects
*/
function httpRequest()
{
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
if (!xmlhttp) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
if (!xmlhttp) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
xmlhttp = false;
}
}
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
/**
* getURL
* mimics getURL function (ASV) for browsers which support XMLHttpRequest
*/
if (typeof getURL == 'undefined') {
getURL = function(url, callback) {
var xmlhttp = new httpRequest();
if (xmlhttp) {
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
callback({status:xmlhttp.status, content:xmlhttp.responseText, contentType:xmlhttp.getResponseHeader("Content-Type")});
}
}
xmlhttp.send(null);
} else {
alert("Sorry, your browser/SVG viewer neither supports getURL nor XMLHttpRequest!");
}
}
}
Old notes still to be incorporated into the text above:
Callback will get passed an object of type viewer::AsyncURLStatus when post operation completes. Reply is assumed to be either ASCII or Unicode text (in UTF-8 or UTF-16 encodings), possibly compressed with gzip or deflate. Callback will get decoded, uncompressed text as a string.
