gpt4 book ai didi

javascript - 类型错误 : $ is not a function in AJAX and Wordpress

转载 作者:行者123 更新时间:2023-11-30 00:33:42 25 4
gpt4 key购买 nike

我尝试在 Wordpress 上通过 AJAX 在 div 上添加内容。我使用 JSON API 从特定类别获取帖子。这是代码:

<div id="content" style="display:none;">This is my test</div>

<script type="text/javascript">


$(document).ready(
function() {
setInterval(function() {$.getJSON('/_jquerydownloaddata',
function(data) {
if (data) {

$("#content").show();
$("#content").html(data)

} else {

$("#content").hide();

}

})}, 5000);
});

</script>

如果我在没有 Wordpress 的情况下在本地运行它,它可以毫无问题地运行。但是,现在我在 $(document).ready 行出现了这个错误:

类型错误:$ 不是函数

最佳答案

$ 更改为 jQuery 并查看是否有帮助。基本上,这个错误是想帮助你——$ 真的不是一个函数,所以你需要验证 jQuery 已经加载到你在此处包含的脚本标签上方的页面上.

关于javascript - 类型错误 : $ is not a function in AJAX and Wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28176444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com