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

查看:21
本文介绍了在 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 将您的脚本注入 .像这样:

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天全站免登陆