Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Ajax Update

  • 02-03-2010 12:15pm
    #1
    Registered Users, Registered Users 2 Posts: 2,110 ✭✭✭


    Hi,
    I have a webpage which is being sent a variable from a c function. Th web page displays the variable fine but as it is constantly changing I need to refresh the page to see the new value.

    I have been looking intp xmlhttprequests and it seems perfect.
    All I want Ajax to do is request the page and display it with a refresh rate of 1 second without having to reload the entire page.

    Any hints?


    D


Comments

  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    I think you want to use the setTimeout() function


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    setInterval, combined with the get function.

    jQuery would make the call and the "replace content" pretty simple
    function refreshAjax() {
      $.get(url,function(data) {
       $("#targetElement").html(data)
      }
    }
    
    $(document).ready(function() {
      expr="refreshAjax()";
      setInterval(expr,1000)
    })
    


  • Registered Users, Registered Users 2 Posts: 2,110 ✭✭✭sei046


    Hmmm.
    Ok, so lets say Im on this page Sensors.stm.
    If I include " %! adc " the page will input a table which is formed inside a c function.

    What I want is a realtimeupdate of this table. To do this the html page sensors has to be refreshed. I dont want this. All I want to do is let the javascript update the variable, then display it.

    Confusing to explain! Thanks for reply guys


  • Registered Users, Registered Users 2 Posts: 3,141 ✭✭✭ocallagh


    1 second is quite fast as it's the client doing the call each time. I would re-write that JS so that the call to refresh the data is only done once a previous cycle is completed. So in effect there is a 1 sec + (x) timeout where x is a network delay or whatever.
    function refreshAjax() {
      $.get(url,function(data) {
       $("#targetElement").html(data);
       setTimeout("refreshAjax()", 1000);
      }
    }
    
    $(document).ready(function() {
      refreshAjax();
    })
    


  • Registered Users, Registered Users 2 Posts: 2,110 ✭✭✭sei046


    ok, will check out that code. This is for data display so there wont be any interaction. I dont have to worry about a consumer!


  • Advertisement
Advertisement