Skip to content

Instantly share code, notes, and snippets.

@StephanieSunshine
Last active December 21, 2015 14:29
Show Gist options
  • Save StephanieSunshine/6319922 to your computer and use it in GitHub Desktop.
Save StephanieSunshine/6319922 to your computer and use it in GitHub Desktop.
Oh javascript how i love you......
var server_list = []
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
//Onload
$(function() {
//jQuery button stuff
$( "button" )
.button()
.click(function( event ) {
event.preventDefault();
});
//jQuery accordian stuff
$( "#accordion" ).accordion({
icons: null,
collapsible: true,
active: false,
heightStyle: "content"
});
//Load json crap
$.ajax({
url: '/query',
async: false,
dataType: 'json',
success: function (response) {
$.each(response, function(key, val) {
// Do processing here
// console.log(val.title);
var start = new Date().getTime();
var url = "http://"+val.ip+":"+val.port+"/query/info";
console.log(url);
var xhr = createCORSRequest('GET', url);
xhr.onerror = null;
xhr.onload = function() { var end = new Date().getTime(); server_list.push([ end - start, val.title, val.ip, val.port, val.descr ]); };
xhr.send();
});
// We should have been sync'd upto this point and have a list
console.log(server_list.sort());
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment