Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- HTML -->
- <ul>
- <li data-id="1">This is a question</li>
- <li data-id="2">Another question</li>
- </ul>
- <!-- /HTML -->
- <!-- Javascript -->
- setTimeout(function(){
- $.ajax({
- url: 'poll.php',
- type: 'GET',
- dataType: 'json',
- success: function(response){
- // Response will be a JSON object returned from the PHP script
- check_changed_questions(response);
- }
- });
- });
- function check_changed_questions(questions){
- for(i=0; i<questions.length; i++){
- var id = questions[i].id;
- var html_question = $('li[data-id=' + id + ']').html();
- var db_question = questions[i].questions;
- if(db_question != html_question){
- // Means the question in the database does not
- // match the one on the page
- }
- }
- }
- <!-- /Javascript -->
- <!-- PHP (poll.php) -->
- <?php
- $sql = "SELECT * FROM questions";
- $data = array();
- $result = mysql_query($sql);
- while($row = mysql_fetch_assoc($result))
- {
- $data[] = array('id' => $row['id'], 'question' => $row['question']);
- }
- echo json_encode($data);
- ?>
Add Comment
Please, Sign In to add comment