Click to See Complete Forum and Search --> : httprequest


Helman
03-26-2006, 07:23 AM
hello!
i want to load 10 diferent pages from one server and display them on 1 page(using div.innerhtml=http.request.responsetext)
i am using httprequest asynchonyc becouse i want to display them in order they returning,and not by the sending order. i mean that:
if page1 much heavier than page2 then even that httprequest requering page1 before page2, server will finish preparing page2 before page1 and i want to present page2 before page1.
in fact i getting page1 first and imideatly after him page2,thats means that page2 is ready much earlier but i am not succeding to recieve him.
my code is:

var httpRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
httpRequest1.open('GET', strURL,true);
httpRequest1.setRequestHeader("Content-Type","text/html; charset=utf-8");
httpRequest1.setRequestHeader("Connection","close");
httpRequest1.onreadystatechange = function(){if (httpRequest1.readyState ==4) {
document.getElementById("div1").innerHTML=httpRequest1.ResponseText}};
httpRequest1.send(null);

var httpRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
httpRequest2.open('GET', strURL2,true);
httpRequest2.setRequestHeader("Content-Type","text/html; charset=utf-8");
httpRequest2.setRequestHeader("Connection","close");
httpRequest2.onreadystatechange = function(){if (httpRequest2.readyState ==4) {
document.getElementById("div2").innerHTML=httpRequest2.ResponseText}};
httpRequest2.send(null);

i guess thats something with multiple requests in same time to one server or i dont know..
any help?
thanks

A1ien51
03-26-2006, 07:31 AM
IT has to do with the size of the page. Apparetly pasge 1 is bigger than 2 hence why it is coming first. You need to develop a queue that loops through instead of just copy and pasting the code over and over.

Why are you loading 10 pages like this in the ifrst place. I think it is not the best use of the XMLHttpRequest Object in my eyes.

Plus your code is IE only.

Eric

Helman
03-26-2006, 08:42 AM
i have aloop for my 10 requests thats not the problem.
i gave you just my test page for 2 requests..
but thats the case
becouse page1 is heavier i want that page2 be displayed before page1
i can see in log that both requests are sent almost together and lets say page1 returns after 2 sec and page2 after 2 sec and 1 i mean 2.1
and without page1 page2 comes back after 0.3 sec.
so i want to see page2 after 0.3 and page1 1.7 sec after thet, all together i will see both of them 2 sec after sending!
can i do that?
:)