Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
574 views
in Q2A Core by
edited by

I want to use auto refresh function in class "qa-q-list" so i use ajax to load this class after a interval X , but this doesnot relaod that div part . Is any body have solution for this problem 

I am currently using this funtion 

 

 
<script>
var refreshId = setInterval(function()
{
     $('.qa-q-list').fadeOut("fast").fadeIn("fast");
}, 5500);
<//script>
 
But above function  work but not refreshing data from database.
so i tried this one using jquery but this also not working below is the code for jquery
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('.qa-main').load('qa-theme-base.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
 
 
</script>
 
I have also search in net i found that using jquery we can achieve that but that require module in seperate php file.
Please if anybody have any suggestion please share here.
 

1 Answer

+1 vote
by
 
Best answer

The funniest thing about this is to watch the seconds tick as it updates... :)

Your code is useless... you need to actually perform an ajax request:

http://api.jquery.com/jQuery.ajax/

This works for me:

<?php
    class qa_html_theme extends qa_html_theme_base
    {
        function doctype() {
            if(qa_post_text('ajax_reload_q_list')) return;
            qa_html_theme_base::doctype();
        }
        function html()
        {    
            if(qa_post_text('ajax_reload_q_list')) {
                $this->q_list($this->content['q_list']);
                return;
            }
            qa_html_theme_base::html();
        }
        function head_custom() {
            if(isset($this->content['q_list'])) {
                $this->output_raw("<script>
    jQuery('document').ready(
        function() {
            startAjaxQListRefresh();
        }
    );
    function startAjaxQListRefresh() {
        window.setTimeout(
            function() {
                getAjaxQList();
            },
            5500
        );
    }

    function getAjaxQList() {
        var dataString = 'ajax_reload_q_list=true';  
        var out = '';
        jQuery.ajax({  
            type: 'POST',  
            url: '".qa_self_html()."',  
            data: dataString,  
            success: function(data) {
                jQuery('.qa-q-list').replaceWith(data);
                startAjaxQListRefresh();
            }
        });
    }
</script>");
            }
        }
    }
  

by
Hi salil,

Could you please help, which find did you put the above code to achieve that?
...