Refreshing and Scrolling JSON

As I continue to try to figure this out, I have a page here that does what it is supposed to do but I would like to make two changes:

1) Is there a way to make the table visible onload?
2) Is there a way to periodically refresh the table without user action?  This page will be on view as races continue and I would like it to continue to refresh.
Bob SchneiderCo-OwnerAsked:
Who is Participating?
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
to load the table automatically, simply call your ajax function:

$( document ).ready(function() {
    var event_id = 6;       //-- set your default ID value here
    doResults(event_id);
});

Open in new window


to do the refresh, you would add a setInterval() function call to your code:

$( document ).ready(function() {
    var event_id = 6;       //-- set your default ID value here
    doResults(event_id);

    setInterval(function(){
        doResults(event_id) // this will run after every 5 seconds
     }, 5000);

});

Open in new window

0
 
Slick812Commented:
greetings  Bob Schneider, , There is much in your page code as Javascript, that does not do what is needed, and the way you have the AJAX setup could be better. you have this button -
     <button id="btnGetData" type="button" style="margin-left: 5px;">View All Results</button>
inside of a FORM, you do not need the <form> at all, also you don NOT need the -
     type="button"  
as this is a button , not an input

In your javescript you have in this -
      $('button#btnGetData').click(function(){

where it gets an event_id  Value with this -
      var event_id=$(this).val();

BUT your button has NO VALUE to get, so you send an "undefined" to your function -
       doResults(event_id);

and this must be a mistake you have the -
       doResults( );
a second time? ? ?


you can use the JQuery  $( document ).ready()   method to call your  doResults( );   function to have the results shown on load.
See the Jquey manual for info about $( document ).ready()  at -
     http://learn.jquery.com/using-jquery-core/document-ready/

Also, if you use a Jquery version Before the version 1.11.0, then your AJAX will not work in the new version of Internet Explorer, you use this -
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

which is an older version of Jquery, and will not work for IE 11
0
 
Bob SchneiderCo-OwnerAuthor Commented:
Thanks all!

BTW, Is this correct?

"}, 5000);"
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
yes, i put it on its own line so I could add the comment on the previous lines. you can have the entire call on a single line if you like
0
 
Bob SchneiderCo-OwnerAuthor Commented:
Thanks!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.