I try to add content on a div through AJAX on Wordpress. I use the JSON API to get posts from a specific category. Here is the code:
<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>
If I run it local without Wordpress, it runs without a problem. However, now I have this error on the $(document).ready line:
TypeError: $ is not a function
$tojQueryand see if that helps. Basically, the error is trying to help you –$really isn't a function, so you'll need to verify that jQuery has been loaded on the page above the script tag that you've included here.$?jQuery(document).ready(function($){...});