BLOG

Tackling AJAX and script tags inside

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


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.

  • nysmallbusinesshub
    March 19, 2015 at 10:29 pm

    I loved as much as you’ll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get got an impatience over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike.

  • missautohof
    June 3, 2015 at 6:58 am

    This post contain a lot of information about recent wheel of events.i hope this article will be helpful for the reader’s.thank you very much for sharing with us.

  • sportsmeetsfood
    June 3, 2015 at 6:56 pm

    I simply want to mention I am beginner to blogging and really enjoyed this web site. Almost certainly I’m want to bookmark your website . You surely have impressive stories. Appreciate it for sharing your webpage.

Leave a comment

Your email address will not be published

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

1 + 4 =

{"type":"main_options","images_arr":"'#ffffff'","enable_ajax":"off","soundcloud_apikey":"","bg_isparallax":"off","bg_slideshow_time":"0","bg_transition":"slidedown","site_url":"http:\/\/digitalzoomstudio.net","theme_url":"http:\/\/digitalzoomstudio.net\/wp-content\/themes\/qucreative\/","blur_ammount":"26","width_column":"50","width_section_bg":"","width_gap":"30","border_width":"0","border_color":"#ffffff","translate_leave_a_comment":"Leave a comment","translate_leave_a_comment_to":"Leave a comment to","is_customize_preview":"off","width_blur_margin":"30","gallery_w_thumbs_autoplay_videos":"off","enable_native_scrollbar":"on","content_enviroment_opacity":"30","menu_enviroment_opacity":"70"}
{"type":"darkfull"}