Skip to content Skip to sidebar Skip to footer

Js Error After Ajax Get/load

i have a wordpress blog where i have post with a flexslider (plugin's name is meta slider). Now i have a page on that blog that loads a div's content dynamically with AJAX from pos

Solution 1:

You are probably not loading the flexslider plugin, are loading it before jQuery or override $ because you're loading several libraries.

In the development tools do you see any files that are not loaded?

In the development tools what sources are loaded? What is the order in which you load the scripts?

     $("");

Returns a jQuery object. You can extend jQuery with more functionality as flex slider is supposed to do but if you don't load it then it won't be available

Solution 2:

I was able to "fix" my problem by doing the following:

First, i changed my ajax call to load the whole page inside the div by this code:

$("#refpage-single-post-container").load(post_link, function() {
} );

I knew this was gonna make the JS work since i saw it work yesterday - but it loaded heavy chunks of unneeded crap of course.

Secondly, i figured out which parts from the page's header and footer seemed to be necessary for the JS to work and it turned out i completely forgot about the footer yesterday night.

I then edited single.php to output only the bare post content, including the following scripts and css from both header and footer. Those were required to load with new post to make the JS work:

<?php$siteurl = get_site_url(); ?><scripttype="text/javascript"src="<?phpecho$siteurl; ?>/wp-includes/js/jquery/jquery.js?ver=1.11.0"></script><?php$post = get_post($_POST['id']);?><divid="single-post post-<?php the_ID();?>"><?phpwhile (have_posts()) : the_post();
                the_content();
    endwhile;?></div><linkrel="stylesheet"id="metaslider-flex-slider-css"href="<?phpecho$siteurl?>/wp-content/plugins/ml-slider/assets/sliders/flexslider/flexslider.css?ver=2.9.1"type="text/css"media="all"><scripttype="text/javascript"src="<?phpecho$siteurl?>/wp-content/plugins/ml-slider/assets/sliders/flexslider/jquery.flexslider-min.js?ver=2.9.1"></script>

So finally, i am able to load the post into that div and have it working. But also i now have to live with the fact that my single.php outputs no full page at all anymore, and is thus quite unusable. (Setting the css display:none somehow wouldnt work on the header, footer, etc since of duplicate id's in the markup perhaps) I think i may not need to display a single post ever on a URL, but it doesnt make me feel good since this breaks a good part of functionality on my theme and this is a production website :/ Any ideas on this?

Post a Comment for "Js Error After Ajax Get/load"