Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onreadystatechange NOT working in IE!!!!

Status
Not open for further replies.

asealy

Programmer
May 2, 2007
18
GB
hello. i have a script that loads content into a div. it works in firefox but not IE. i have debugged and determined where it stops working, i just don't know why it ain't working. here is the code:

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

// stops working here
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
//alert('test');
}
page_request.open('GET', url, true)
page_request.send(null)
}

can anybody provide a solution please.

thanks in advance
 
the "onreadystatechange" method must first check that the state is 4 and that the page is "200 OK" before you call the "loadpage" function... Google the HTTPRequest..

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
hi. thanks for the info. i think my script already does that. here's the whole thing:

var loadedobjects=""
var rootdomain="var page_request = false;

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
// no funciona de aqui
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
//alert('test');
}
page_request.open('GET', url, true)
page_request.send(' ')
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}


any suggestions please??

thanks
 
asealy said:
any suggestions please??

I have one. Using the [tt][code][/code][/tt] tags and indenting your code so that it's actually readable gives you a much greater chance at getting a decent answer.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
It's a good practise to end every command with a semicolon and also use brackets in the if/else statements.. It's easier to read. And as [navy]dwarfthrower[/navy] said, use the [tt][ignore]
Code:
[/ignore][/tt] so we can read it too..

BTW, why do you check the [tt][maroon]window.location.href.indexOf("http")==-1[/maroon][/tt]?

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top