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 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    79
    Thanks
    7
    Thanked 0 Times in 0 Posts

    body onload issue

    i cannot understand, am i making the same mistake each time but my <body onload="startChecking()">

    does not want to load again??

    here my full code:
    Code:
    <head>
        <script language="JavaScript" type="text/javascript">
            var sendReq; 
            var receiveReq;
            var lastmessage = 0;
            var mTimer;
            
            function startChecking()
            {
                receiveReq = new XMLHttpRequest();
                console.log("1234");
                getNewMessage();
            }     
                    
            function getNewMessage()
            {
                if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
                {
                    console.log(receiveReq.readyState);
                }
                mTimer = setTimeout('getNewMessage();',30000);
            }   
    </script>
    </head>
    
    <body onload="startChecking()">
    
    //more code here
    
    </body>
    i just want the console.logs to execute then i will continue with the rest of my code...

    please help?
    thank you

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    The code is absolutely fine like this. There has to be another problem ... any other Javascript on the page?

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by devnull69 View Post
    The code is absolutely fine like this. There has to be another problem ... any other Javascript on the page?
    I also tested the code (in google chrome ) and is ok, I see 1234 and various 0 in console .
    In IE your code gives compilation errors (console is undefined ) and then onLoad don't work.

  • #4
    New Coder
    Join Date
    Jan 2011
    Posts
    79
    Thanks
    7
    Thanked 0 Times in 0 Posts
    thanks all, used window.onload and now it works...


  •  

    Posting Permissions

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