在Joomla 3上刷新div [英] Refresh div on Joomla 3

查看:65
本文介绍了在Joomla 3上刷新div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有刷新div的脚本. 在此脚本中加载了文件test.php并以正常代码显示在div#welcome-desc上,该脚本有效,但joomla无效.我需要刷新选择的所有页面进行一次潜水. test.php的地址正确.脚本JS正常工作,但对Joomla(3.X)(自定义html模块)的内容无效,我在做什么错了?

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>

推荐答案

首先,您应确保脚本处于noConflict模式,因为这是Joomla导入jQuery的方式.其次,我不确定要在何处添加此脚本,但是在调用文件时应定义站点的根目录.第三,我建议使用Joomla API将脚本注入到<head>中.像这样:

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

这篇关于在Joomla 3上刷新div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆