Created
June 12, 2014 09:48
-
-
Save magixsource/68faed725d7e884eb11e to your computer and use it in GitHub Desktop.
blocking function depend non-blocking function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XHR lib use jquery | |
// jsonp url | |
var url = "http://www.google.com/jsonp/search.html" | |
// query keys | |
var array = new Array("google.com","baidu.com","yahoo.com","bing.com","soso.com"); | |
//$.getJSON is a non-blocking function,load jsonp data here | |
function nonBlockingLoad(o){ | |
$.getJSON(url+"?query="+o+"&type=text&nodeNo=87&callback=?",function(data){ | |
if(data.pass){ | |
//TODO | |
}else{ | |
blockingInvoke(); | |
} | |
}); | |
} | |
// This is a normal blocking function | |
function blockingInvoke(){ | |
var item = array.pop(); | |
if(item){ | |
nonBlockingLoad(obj); | |
} | |
} | |
// trigger | |
$("#btn").bind('click',function(){ | |
blockingInvoke(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment