onreadystatechange NOT working in IE!!!!

This is a discussion on "onreadystatechange NOT working in IE!!!!" within the JavaScript Forum section. This forum, and the thread "onreadystatechange NOT working in IE!!!! are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 18th, 2008, 09:10
New Member
Join Date: Jan 2008
Location: essex
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
onreadystatechange NOT working in IE!!!!

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:
Code: Select all
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

Last edited by Rakuli; Jan 18th, 2008 at 09:15. Reason: wraped some [code] tags around it and removed completely unnecessary links
Reply With Quote

  #2 (permalink)  
Old Jan 18th, 2008, 09:16
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: onreadystatechange NOT working in IE!!!!

If it's working in FF and gets up to readystatechange in IE I would think it's not your ajax function.. try sending an empty string rather than NULL in your send request as well
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Jan 18th, 2008, 09:23
New Member
Join Date: Jan 2008
Location: essex
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: onreadystatechange NOT working in IE!!!!

thanks. i tried that but it still didn't work. i ain't too good with javascript so i don't know where to go next. any other solutions would be appreciated.

thanks
Reply With Quote
  #4 (permalink)  
Old Jan 18th, 2008, 09:26
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: onreadystatechange NOT working in IE!!!!

Can you post the code that is the loadPage function?... I assume you have tested at each part of the exception to make sure the XHTTP request is actually be processed by IE activeX?
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Jan 18th, 2008, 09:38
New Member
Join Date: Jan 2008
Location: essex
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: onreadystatechange NOT working in IE!!!!

ok. here's the entire script:

Code: Select all
var loadedobjects=""
var rootdomain="<A href="http://"+window.location.hostname">http://"+window.location.hostname
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[i]
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
}
}
}
thanks
Reply With Quote
  #6 (permalink)  
Old Jan 18th, 2008, 09:54
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: onreadystatechange NOT working in IE!!!!

Okay, you need to declclare page_request into the global namespace. Either that, or assign load page as a member method of the page_request object.

What I mean is declare page_request outside of any function.

I would also recommend adding semi colons to the end of each statement to avoid possible misinterpretation of lines.

Code: Select all
var loadedobjects=""
var rootdomain="<A href="http://"+window.location.hostname">http://"+window.location.hostname;
var page_request = false;


function ajaxpage(url, containerid){

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){return;}
    }
}
else
return false;


// no funciona de aqui
page_request.onreadystatechange=loadpage; // attach the function directly to this even
page_request.containerid = containerid; // attach the container as awell

page_request.open('GET', url, true)
page_request.send(' ')
}
function loadpage(){
    if (this.readyState == 4 && (this.status==200 || window.location.href.indexOf("http")==-1))
       document.getElementById(this.containerid).innerHTML=this.responseText;
}
function loadobjs(){
    if (!document.getElementById)
        return;
    for (i=0; i<arguments.length; i++){
       var file=arguments[i];
       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
}
}
}
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #7 (permalink)  
Old Jan 18th, 2008, 10:38
New Member
Join Date: Jan 2008
Location: essex
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: onreadystatechange NOT working in IE!!!!

hi. i tried your suggestion but again had no luck so i put it back how it was. it actually stopped working for some reason in all browsers.

i must be following your instructions wrongly. if you don't mind and have time i have zipped the files here
http://www.ministryinart.com/avance/script.zip

if you feel like it can you have a look please. its the terms and privacy buttons im using.

thanks again for your time
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS not working in IE? Jgag Web Page Design 2 Jun 5th, 2008 11:14
Why is this not working! Jack Franklin PHP Forum 7 Mar 25th, 2008 10:34
PNG - IE not working Phixon Web Page Design 3 Nov 30th, 2007 13:47
PHP not working toolmania1 PHP Forum 1 Nov 1st, 2006 05:57
Png not working timmytots Graphics and 3D 11 May 14th, 2006 07:06


All times are GMT. The time now is 01:17.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43