Quantcast
Channel: Javascript – Digital Zoom Studio
Viewing all articles
Browse latest Browse all 15

Tackling AJAX and script tags inside

$
0
0

So recently I had to make ajax requests that pull in a piece of page with some scripting inside. The context does not matter much, what matters is the script executed fine on my localhost but not as a WordPress installation in a WP blog. After some head banging turns out that in my localhost I was using jQuery 1.9.1 and WP uses 1.8.3 .

So jQuery 1.9.1 seems to find the script tags too in the pulled ajax content. But what interests me is the WP plugin functionality. I could deregister the 1.8.3 and register the 1.9.1 but that is a very very bad practice. So I prefer a dirty approach better then a bad practice that could damage others.

I wrap my script in a invisible div like so

<div class="toexecute" style="display:none">
                jQuery(document).ready(function($){
                    var videoplayersettings = {
                        autoplay : "off"
                        ,videoWidth : "100%"
                        ,videoHeight : 300
                        ,constrols_out_opacity : 0.9
                        ,constrols_normal_opacity : 0.9
                        ,settings_hideControls : "off"
                        ,design_skin: "skin_aurora"
                        ,responsive: "on"
                    };
                    $('#vphistory').vPlayer(videoplayersettings);
                })
            </div>

Then in the javascript just do

jQuery('.toexecute').each(function(){
    var _t = jQuery(this);
    if(_t.hasClass('executed')==false){
        eval(_t.text());
        _t.addClass('executed');
    }
})

at the end of the document and at the end of each complete ajax request.


Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles



Latest Images