Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Polling in JQuery.. must be a better way?

Posted on 2011-09-21
3
277 Views
Last Modified: 2012-05-12
Hi,
I'm using Jquery to update a couple divs on a timer and all works well. My problem is in order to accomplish it I have to run separate php files to query the database for each div so it returns the proper data to display for that div.

Is there a way I can simply use one query, pass back all the data and have it populate the appropriate divs? My code I'm using is below:
 
<script>
 $(document).ready(function() {
 	 $("#contest_status").load("application/modules/account/scripts/contest_status.php?account_id=4");
 	 $("#contest_title").load("application/modules/account/scripts/contest_title.php?account_id=4");


   var refreshId = setInterval(function() {
      $("#contest_status").load('application/modules/account/scripts/contest_status.php?account_id=4&randval='+ Math.random());
      $("#contest_title").load('application/modules/account/scripts/contest_title.php?account_id=4&randval='+ Math.random());

   }, 6000);
   $.ajaxSetup({ cache: false });
});
</script>

Open in new window


Thanks for any help.
0
Comment
Question by:tjyoung
  • 2
3 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36575764
Yes, see this get method
http://api.jquery.com/jQuery.get/

in the success handler, you can parse data and place it in appropriate div
0
 
LVL 1

Author Comment

by:tjyoung
ID: 36577135
Great, that looks like the right direction.
Can you give me an idea what the code would look like with a timer?
Not particularly good at this.
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36577647
function getData()
{
  //ajax call
  $.get('ajax/test.html', function(data) {
     //loading data in various divs
    $('.result').html(data);
    //alert('Load was performed.');
    setTimeout("getData()", 5*1000); //calling this method again after 5 seconds
  })
}
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question