.js file can't take more than 1 refresh call?

alt=
Ekwe
@ekwe
10 years ago
212 posts
Trying to refresh some divs at different times. but when i add the refresh code. they all stop working. I put this code twice for 2 different calls, still no work

// Side charts

var auto_refresh_sm = setInterval(
function ()
{
$('#side_charts').load(core_system_url +'/charts-mini').fadeIn("slow");
}, 60000); // refresh every 60000 milliseconds

// End Side charts

});
updated by @ekwe: 04/10/14 02:28:45PM
michael
@michael
10 years ago
7,714 posts
Javascript is pretty difficult to debug at the best of times. Trying to figure out what your issue is with just a small snipit of code is very difficult.

Can't offer any advice other than javascript is fickle. Make sure your page validates. Then work through it one step at a time until you find where it goes wrong.
paul
@paul
10 years ago
4,326 posts
I have a JS function to periodically update a div. It gets called once in the footer template and then runs all the time the page is open. It uses an ajax call to get the data, and it only updates the div if the returned data is different from the previous returned data.
function jrSocialModuleAlerts(timeout) {

    var _html = new Array('','');
    var url = core_system_url + '/socialmodule/alerts/__ajax=1';
    timeout = timeout * 1000;

    setInterval(function() {
        $.ajax({
            type:'POST',
            url: url,
            data:{},
            dataType:'json',
            success:function (data) {
                if (data.OK == 1) {
                    // Update profile alerts
                    if (typeof data.alerts !== "undefined") {
                        _html[0] = data.alerts;
                        if (_html[0] != _html[1]) {
                            $("#alerts").fadeOut("slow").html("");
                            var interval = setInterval(function() {}, 500);
                            $("#alerts").fadeIn("slow").html(data.alerts);
                            _html[1] = data.alerts;
                        }
                    }
                    else {
                        $("#alerts").fadeOut("slow").html("None found");
                    }
                }
                else {
                    $("#alerts").html(data.error);
                }
            },
            error:function () {
                $("#alerts").html('an error was encountered - please try again');
            }

        });
    }, timeout);
}
hth
Pa


--
Paul Asher - JR Developer and System Import Specialist
brian
@brian
10 years ago
10,148 posts
You are going to have to use $.ajax instead of $.load - that way you can set the "cache" param to false (by default it is true):

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

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags