开发者

jquery: on demand plugin loading fails if alert not present

I'm using the jQuery Loader plugin to load files on demand- tagit plugin.

The issue is that if I add an alert to the callback function fired on load the plugin loaded seems to work, if I remove the alert, the plugin fails.

Any ideas why is this happening?

$(document).ready(function(){    
   $("#mytags").Loader(
                {
                    url: [
                        'media/plugins/tagit/css/jquery-ui/jquery.ui.autocomplete.custom.css',
                        'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js',
                        'media/plugins/tagit/js/jquery-ui/jquery-ui-1.8.autocomplete.min.js',
                        'media/plugins/tagit/js/tag-it.js'
                    ],
                    success: function(target) {
                        //alert('loaded');                  
                         $(target).tagit({
                            availableTags: ["tag1","tag2", "tag3"],
                            values: ["tag2"]
                        });
                    }
                }
 });

Im testing this on my lo开发者_Python百科cal XAMP environment.


The possible reason why blocking code execution with alert() helps is that, while JavaScript execution stops (including intervals and timeouts), external resources (JS, CSS, images, and xmlhttprequests) may finish loading. But, again, until the code following the alert() completes, none of these external scripts will run and no DOM events will fire.

An example when alert() makes a difference: http://jsfiddle.net/p9Nff/


It's problaly related with async, do you try to force async to false?

When the alert open the script have time to load your plugins. or it's what Alexey said, your DOM is not ready, put your code into $(function(){ /code here/ });

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜