Hi there,
I am trying to use JavaScript to get the source of a web page, and save the source in a variable.
Problem is, the part that gets the source (responseText) is inside of a function, and so I can’t bring it out of the function because of how it works.
Here is my code:
[CODE]
function load_xml(URL) {
var xmlObj = new XMLHttpRequest();
xmlObj.open(“GET”, URL, true);
xmlObj.onreadystatechange=function() {
if (xmlObj.readyState==4) {
// This variable now contains the source
var source = xmlObj.responseText;
}
}
// Now, the variable source is empty, so I can’t return it
return source;
xmlObj.send(null);
}
var source = load_xml(“http://www.google.com”);
Perhaps my comments explain the problem?
Thanks,
Jason