jquery - 在 10 秒内刷新 wordpress 网站中的 div 内容
问题描述
我正在使用 WordPress。我需要每 10 秒刷新一次 div。div 的内容是一个简码,其中包含来自数组的图像。
div 名称是 header_image 并且创建短代码的代码存在于 functions.php
所以添加了这段代码,没有任何效果
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
setInterval(function() {
$(".header_image").load("functions.php");
}, 1000);
});
</script>
div的内容
<div class="header_image">
<a href="<?php echo $data[0]; ?>">
<img src="<?php echo $data[1]; ?>">
</a>
</div>
解决方案
如果浏览器返回 404 Not found,你应该使用绝对路径而不是相对路径。
示例:如果您的 functions.php 文件位于 /wp-content/themes/theme-name/functions.php 中,则正确的代码应为:
$(".header_image").load("/wp-content/themes/theme-name/functions.php");
推荐阅读
- python - 如何循环地将 3 个值添加到更大的列表中
- c++ - 如何在 C++ 中生成唯一 ID 和创建 ID 时的日期表示
- python - 具有多个参数的记录格式插值
- data-structures - 在数组中插入元素的空间复杂度
- python - 通过rest api调用编写python SDK并且需要知道request.session是否应该关闭
- mysql - 如何比较 3 个或更多表的行数并返回布尔值?
- java - android.view.InflateException:二进制 XML 文件复选框
- html - 为什么我应用固定定位时页脚会消失?
- r - R中函数cov()的协方差矩阵输出不同于Eviews和Excel中的协方差矩阵输出
- c - 如何将指针插入到数组列表中?