Displaying Ajax data and using timers properly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shawnwperkins@gmail.com

    Displaying Ajax data and using timers properly

    Hi Guys,

    I'm new to Javascript and have a couple of questions that I hope
    someone could quickly answer for me.

    First, I'm trying to modify an example Ajax script to fit my needs.

    The script is located here:



    I'm trying to display return data from my existing script, and I'm a
    little confused on how to display the returned variables within my Web
    page. Currently the author of the 'example' script has the following
    code embedded within the HTML:

    <form action="/">

    <div id='customTimeL abel' class='timeLabe l'></div>

    <div align="center">
    <input type="hidden" id="customTime " value="Refresh" />
    </div>

    </div>
    <div align="center"> </div>

    </form>

    The author displays this form and also has a button to create an
    additional action when the button is pressed. I removed the button and
    just want to display the variables, I do not want to have a form as he
    did. Is there a alternate way of doing this? When I embed this in my
    code it takes up too much real estate on the Web page.


    Second, there is a setInterval timer used that periodically goes to
    the server and refreshes the data. I have created a function,
    'volup()' that stops the timer 'clearInterval( interval)' and displays
    a new message for a few seconds, then my script is supposed to restart
    the setInterval timer. Everything seems to work ok with the exception
    of the setInterval restart. Could someone have a look at my code and
    give me some suggestions? The problem is on the last line of the
    volup() function, this command never seems to restart the timer. Also
    I've noticed that my setTimeout timer can become very erratic at
    times, not following my specified timing of 3 seconds, but this only
    happens once in a great while and is very intermittent.

    Thanks in advance,

    Shawn


    ajaxCaller.shou ldDebug = false;
    var timeURL = "cgi-bin/test?h=1";
    //var timeURL = "tickercontent. txt";
    window.onload = function() {
    // $("defaultTime" ).onclick=reque stDefaultTime;
    // $("customTime") .onclick=reques tCustomTime;
    requestCustomTi me();

    interval=setInt erval(requestCu stomTime, 1500);
    }

    function volup(){

    clearInterval(i nterval)
    showCustomTime( "Change Source", "");

    a="requestCusto mTime();"

    setTimeout(a, 3000);
    clearTimeout(t)

    interval=setInt erval(requestCu stomTime, 1500)

    }

    function requestCustomTi me() {
    var callingContext = Math.round(Math .random() * 100);
    ajaxCaller.getP lainText(timeUR L, showCustomTime) ;


    }

    function showCustomTime( text, callingContext) {
    var customTimeLabel = $("customTimeLa bel");
    customTimeLabel .innerHTML = text + "." + callingContext;
    }

  • Conrad Lender

    #2
    Re: Displaying Ajax data and using timers properly

    On 2008-09-28 01:32, shawnwperkins@g mail.com wrote:
    Currently the author of the 'example' script has the following
    code embedded within the HTML:
    >
    <form action="/">
    >
    <div id='customTimeL abel' class='timeLabe l'></div>
    >
    <div align="center">
    <input type="hidden" id="customTime " value="Refresh" />
    </div>
    >
    </div>
    <div align="center"> </div>
    >
    </form>
    Then he should go and validate his code, I'd say...

    The kind of question you're asking is not much fun to answer, I'm
    afraid. We're supposed to debug somebody else's library, which has been
    modified, and now it doesn't work anymore. It would be a lot easier if
    you could sort of ask a more contained question.
    ajaxCaller.shou ldDebug = false;
    I don't know anything about ajaxCaller. Maybe shouldDebug can help?
    var timeURL = "cgi-bin/test?h=1";
    //var timeURL = "tickercontent. txt";
    window.onload = function() {
    // $("defaultTime" ).onclick=reque stDefaultTime;
    // $("customTime") .onclick=reques tCustomTime;
    requestCustomTi me();
    >
    interval=setInt erval(requestCu stomTime, 1500);
    }
    >
    function volup(){
    >
    clearInterval(i nterval)
    showCustomTime( "Change Source", "");
    >
    a="requestCusto mTime();"
    >
    setTimeout(a, 3000);
    clearTimeout(t)
    What's "t"?
    interval=setInt erval(requestCu stomTime, 1500)
    So, in three seconds, requestCustomeT ime will be called twice? Once from
    setTimeout() and once from setInterval(). That might explain the
    "erratic" behavior.


    - Conrad

    Comment

    Working...