Hi.
Is it possible to use an array
created by a XMLHttpRequest
in a function called in
window.onload.
For instance:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
var mylinks= new Array();
var req = null;
function processReqChange() {
if (req.readyState == 4 && req.status == 200 ) {
xml= req.responseXML.documentElement;
var item= xml.getElementsByTagName('item');
for(var i=0;i<item.length;i++){
mylinks[i]= new Array();
for(var y=0;y<item[i].childNodes.length;y++){
if(item[i].childNodes[y].tagName=='id' || item[i].childNodes[y].tagName=='title'){
mylinks[i].push(item[i].childNodes[y].firstChild.data);
}
}
}
}
}
function loadUrl( url ) {
if(window.XMLHttpRequest) {
try { req = new XMLHttpRequest();
} catch(e) { req = false; }
} else if(window.ActiveXObject) {
try { req = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try { req = new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) { req = false; }
} }
if(req) {
req.onreadystatechange = processReqChange;
req.open('GET', url, true);
req.send('');
}
}
loadUrl('admin/xml/items.xml');
function test()
{
/* ERROR mylinks IS NOT DEFINED */
alert(mylinks);
}
window.onload= function(){
test();
}
</script>
</head>
<body>
<body>
</body>
</html>
I'd like to develop a sort
of paging to allow a quick
look to the articles in my
blog (only for the titles)
but guess you I've got a lot
of hassles to retrieve mylinks :o
Thanks in advance.
Bye.