I'm trying to make use of XMLHTTP object, but I've come across a
problem.
It seems that there is no way to create dynamic array of such XMLHTTP
objects (to make several requests) and handle them properly.
I was trying to use such code:
<script lang="javascript">
function handleOnReadyStateChange() {
if (this.readyState==4) {
//some actions
}
}
function createObjArray() {
var XmlHttp = new Array();
for (var i = 1; i<=10; i++) {
XmlHttp[i] = new ActiveXObject("Msxml2.XMLHTTP");
XmlHttp[i].open("GET", url, true);
XmlHttp[i].onreadystatechange = handleOnReadyStateChange;
}
}
createObjArray();
</script>
Unfortunately when event handler function is accessed, 'this' isn't
set to an object which fired event.
I was doing literally EVERYTHING (or at least I think so) to make it
work but ... with no success.
Behavior of this handler is somehow different from what I was used to,
because I could with no problem do similiar task with Image object.
<script lang="javascript">
function handleImgOnLoad() {
document.getElementById(this.name).src = this.src;
document.getElementById(this.name).width = Math.round(this.width/4);
document.getElementById(this.name).height =
Math.round(this.height/4);
}
function createImageArray {
var images = new Array();
for(i=1;i<=10;i++) {
images[i] = new Image();
images[i].src = 'some_url';
images[i].name = i;
images[i].onload = handleImgOnLoad;
}
}
createImageArray();
</script>
So my guess is that problem lies in XMLHTTP object which doesn't set
reference to itself in its event handler.
Does anyone knows if it is possible to do what I'm trying to do ?
I would really appreciate any help.