I have this url to call the taxonomy.php by pressing the button with the code beneath to show filtered posts:


This is the JS I am using:

$("#hot a").click(function(){

    var post_id = $(this).attr("rel")
    $(".postbox_wrapper").html('<span class="filter_posts"><img src="<?php bloginfo ('template_directory'); ?>/images/287.gif"></span>');
    $(".postbox_wrapper").load(jQuery(this).attr("href") + " .postbox_wrapper")
    return false;


The call works perfectly - the content show up without pagereload - as I wish.

The problem is, that JS is not loaded on the ajaxloaded pages and I really don't get it to load. I tried out many versions, I found on stackexchange, but nothing worked out.

For example this needs to be loaded into the ajaxed call: http://myname.disqus.com/count.js?ver=3.4.1

Has anybody an idea?

Thanky you very much.


  • I think this is maybe beyond the scope of WordPress Answers, as it's not specific to WordPress. You're not loading a page via AJAX, you're loading specific elements from one DOM into an existing DOM.
    – Milo
    Commented Jul 22, 2012 at 14:56
  • Are you saying you want JS to load on the actual AJAX call? If for some reason that's the case, you might need to dig into server-side vs. client-side processing. Commented Jul 23, 2012 at 1:58

2 Answers 2


Try this code in your complete callback of the load function:

    jQuery(this).attr("href") + " .postbox_wrapper",
    function(response, status, xhr) { // complete callback

        // create a empty div
        var div = document.createElement('div');
        // fill div with response
        div.innerHTML = response;
        // take correct part of the response
        var ref = $($(div).find('.postbox_wrapper').html());
        // filter response for script tags
        ref.filter('script').each(function () {
            // execute the scripts
            $.globalEval(this.text || this.textContent || this.innerHTML || '');

I would also also recommend that you add a error message if the call fails. See example 2 on http://api.jquery.com/load/

I had a hard time to figure that out, I tried all the answers found on stackoverflow. Finally I found this german site. There you can see the full code: http://labor.99grad.de/flash/agentur/wiesbaden/jquery/script-tag-bei-ajax-response-ausfuhren/

  • Hi Xsonic - thank you very much for th reply. I tried your code. It seems to be exactly what I need. It's not working so far - where should I put the code exactly? Thank you!!
    – ad2003
    Commented Jul 22, 2012 at 19:37
  • 1
    I edited the code above to make it cealrer
    – xsonic
    Commented Jul 23, 2012 at 8:19

I ended up with this code:

$("#fokus a").click(function(){

    var post_id = $(this).attr("rel");
    $(".postbox_wrapper").html('<span class="filter_posts"><img src="<?php bloginfo ('template_directory'); ?>/images/287.gif"></span>');
    $(".postbox_wrapper").load((jQuery(this).attr("href") + " .postbox_wrapper"), function() {
        $.getScript("http://check.disqus.com/count.js?ver=3.4.1", function() {
            //alert('first Load was performed.');
    //alert('second Load was performed.');
    return false;

This works so far. Thank you for your help!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.