This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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>
P.S. I got this from the http://octobercms.com/docs/ajax/update-partials document page
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.
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
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
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