开发者

Order of jquery and javascript functions

I have a feeling I'm missing something obvious, but...

All my neat jQuery functions are being forced to wait by a particularly slow-moving javascript api call from within the body of the page. I'd like to have the jQuery run first, and then the api when that's done. Is 开发者_如何学JAVAthere a standard way of imposing the order?


easy workaround, call your api within a setTimeout statement.

Example:

$(document).ready(function(){
     // beautiful jQuery code here
     setTimeout(function(){
        // terribly slow code here
     }, 100);
});

It is in general a good idea to use setTimeout on heavy code/DOM manipulation. It will avoid the browser from "freezing".


Well if you just want the jquery before the javascript, do this:

function japi(){
   japi.dosomething();
   //Your api part here
}

$("#test").html("something");
//Lots of jquery here
japi();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜