Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts

    function doesnt get called in ie

    i am using this function to permanently call from a database a string wich represent a background color value so i can get a permanent redraw but the function doesnt get called in ie. any thoughts appreciated

    Code:
    var p=new xhr()
    function getajax(){
    p.open('get',"pid_01_ajax_query.php?",true)
    p.send(null)
    p.onreadystatechange=function(){
       if (p.readyState == 4) {
      var div=document.getElementById("thediv").style.backgroundColor=p.responseText;
     //alert("o")
    setTimeout('getajax()',100)
                 }
       }
    }
    
    getajax()

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    This does work in Mozilla/Firefox, Safari or Opera?

    Can we see the 'xhr' class? Does it test for browser type and return the correct XMLHttpRequest or ActiveXObject?

    Try changing the method order to open, onreadystatechange, send.

    BTW, the setTimeout call should simply reference the function name, e.g. 'getAjax', not 'getAjax()'.

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    the xhr class is simple and does reference the ie methods:
    Code:
      function xhr(){
    var xmlHttp=null;
    try{xmlHttp=new XMLHttpRequest();}
    catch (e){
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }
    i try setTimeout('getajax',100), but still nothing on ie,
    yep it works on safari and ff

  • #4
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    A couple more thoughts..

    What version of IE?

    I'm wondering if it has to do with your selector:
    Code:
    var div=document.getElementById("thediv").style.backgroundColor=p.responseText;
    Throw a couple of alert()'s in there and verify that IE actually is using an XHR call and returning text to the page. If so, it might simply be your CSS selector.

    Also, I note that your syntax is missing some semicolons, IE's scripting engine can be a buggaboo about things like that.

  • #5
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    ok thanks, i'll keep on debugging

  • #6
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    I finally find out , ie was caching the timeout i added this:
    Code:
    p.setRequestHeader('If-Modified-Since','Wed, 05 Apr 2006 00:00:00 GMT');
    and the setTimeout function worked.

  • #7
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ah, the old IE caching problem. I know it well.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •