Refresh div on Joomla 3

给你一囗甜甜゛ 提交于 2019-12-11 09:48:57

问题


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>

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/26388191/refresh-div-on-joomla-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!