Refresh div on Joomla 3

2019-08-14 05:08发布

I have script to refresh div. In this script loaded file test.php and display on div # welcome-desc in normal code this script is work, but not joomla. I need refresh selected one dive to all pages. Address to test.php is correct. The script JS works correctly but not work content to Joomla (3.X ) (custom html module ) What am I doing wrong ?

<script>

$(function(){
    setInterval(function(){ 
         $("#welcome-desc") .load("dc/test.txt");
    }, 3000);
});

</script>

2条回答
戒情不戒烟
2楼-- · 2019-08-14 05:27

Custom html module may filter the contents of your script and not let them display properly.

First option (recommended) is to create a simple hello_world module using this tutorial and implement your js code via addScriptDeclaration().

Second option is to get a ready made module for custom code in modules from this list.

Hope this helps

查看更多
我命由我不由天
3楼-- · 2019-08-14 05:36

Firstly, you should ensure you script is in noConflict mode as this is how Joomla imports jQuery. Secondly, I'm not sure where you're adding this script but you should define the root of your site when calling a file. Thirdly, I would suggest using Joomla API to inject your script into the <head>. Like so:

<?php
  $doc = JFactory::getDocument();
  $js = 'jQuery(document).ready(function($){
            setInterval(function(){ 
               $("#welcome-desc").load("' . JUri::root() . '.path/to/dc/test.txt");
            }, 3000);
         });';
  $doc->addScriptDeclaration($js);
?>

I would also suggest you check your browser console for any errors

查看更多
登录 后发表回答