new information begins
I was able to make a little headway by changing one line in the "existing" code (that is, in the code I am borrowing), replacing responseXML
with responseText
. That fixed a key problem in that the variable details
now contains the desired data.
I also noticed while looking at "working example" link containing util.js
that an additional function is being employed xmlParse(str)
. I don't see or understand how xmlParse(str)
is used, but that likely is my naiveté with respect to javascript.
function xmlParse(str) {
if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined') {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
}
So is the new version of Google Maps (V3) using XML when it did not before, or what?
Anyhow, I will likely need to open a new question about the next error I already am experiencing in main.js
, whatever that is.
new information ends
a complete rewrite begins
This first script is available here. I have added some console.log()
results to show intermediate results that confirm that the information is contained in request.responseText
.
/**
* Returns an XMLHttp instance to use for asynchronous
* downloading. This method will never throw an exception, but will
* return NULL if the browser does not support XmlHttp for any reason.
* @return {XMLHttpRequest|Null}
*/
function createXmlHttpRequest() {
try {
if (typeof ActiveXObject != 'undefined') {
return new ActiveXObject('Microsoft.XMLHTTP');
} else if (window["XMLHttpRequest"]) {
return new XMLHttpRequest();
}
} catch (e) {
changeStatus(e);
}
return null;
};
/**
* This functions wraps XMLHttpRequest open/send function.
* It lets you specify a URL and will call the callback if
* it gets a status code of 200.
* @param {String} url The URL to retrieve
* @param {Function} callback The function to call once retrieved.
*/
function downloadUrl(url, callback) {
var status = -1;
var request = createXmlHttpRequest();
if (!request) {
return false;
}
request.onreadystatechange = function() {
if (request.readyState == 4) {
try {
status = request.status;
} catch (e) {
// Usually indicates request timed out in FF.
}
if (status == 200) {
console.log(request.responseText);
console.log(request.responseXML);
console.log(request.status);
callback(request.responseXML, request.status);
request.onreadystatechange = function() {};
}
}
}
request.open('GET', url, true);
try {
request.send(null);
} catch (e) {
changeStatus(e);
}
};
The key part of my script is as follows, and the problem is that details
is always "null" as can be seen from the readout of the log further below. But I can also see from the console.log(request.responseText)
that the data I need is really available.
downloadUrl("details.txt?place=Playground",function(details) {
console.log('details: '+details);
if (details) {
var lines = details.split("\n");
}
}
Below is the console log. The first line is the information I hope to capture in the variable details
and is the value of request.responseText
because it represents a map pin.
How do I alter my code, or even the existing code that was provided, to hook up my variable details
with the result of request.responseText
in the existing code?
ahdkZXZ-c2ltcGxpZnljb25uZWN0aW9uc3IlCxIFR3JvdXAiClBsYXlncm91bmQMCxIDUGluGICAgICAgIAKDA Thu 06 12 2014 1444 29.1109258712 -81.4114379883 Dad 0 0
util.js:42
null util.js:43
200 util.js:44
details: null ?place=Playground:114
The working example of downloadUrl()
is here. (Part of my confusion about understanding how to adapt the working example is that it uses XML, which is not involved in my usage.)
a complete rewrite ends