This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

simpltekonline20120
simpltekonline20120

I'm using AJAX to update a partial on a page every few seconds with a setInterval function, but for some reason it just throws an alert popup "AJAX handler 'onRefreshTime' was not found." Here's the code I'm using as it is placed in my layout:

</body>
<script src="{{ 'assets/vendor/jquery.js'|theme }}"></script>
<script src="{{ 'assets/vendor/bootstrap.js'|theme }}"></script>
<script src="{{ 'assets/javascript/app.js'|theme }}"></script>

{% framework extras %}
{% scripts %}

<script>
    jQuery(document).ready(function($) {
        setInterval(function () {
            $.request('onRefreshTime', {
                update: { msgs: '#msgs' }
            })
        }, 3000);
    });
</script>

And here is the partial as it is placed on my page:

<div id="msgs">
    {% partial "msgs" %}
</div>
simpltekonline20120
alxy
alxy

Where did you define the onRefreshTime handler? It should be either in your pages or layouts code section, or in one of your components. In the latter case, I would recommend to prefix the handler name with the alias.

simpltekonline20120
simpltekonline20120

Define the handler?? From the documentation, I just assumed that was some built-in method or function within October...now I have no idea what I'm doing...

What would I even define it as?

Last updated

simpltekonline20120
simpltekonline20120

I added an empty:

function onRefreshTime() {

}

And that seemed to do it, but now I don't get how this even works; what is the point of this function than just to "make it work"?

Last updated

aaron.humphreys
aaron.humphreys

Because its AJAX. The Javascript is calling a PHP function. With that you can send data through the AJAX request to the PHP function. Then do things with said data, then return different results.

In this instance, within the php function, you would want to be getting fresh data for your msgs variable, Else each time you are calling this refresh, you are ajaxing the same 'static' data in each time.

See: https://octobercms.com/docs/ajax/handlers#returning-data-from-handlers

Last updated

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.