для асинхронной отправки запроса можно использовать такой вариант
window.Callbacks = {};
function Script(url, callback) {
var performed = false,
_Fname = String(Math.random()).slice(2);
url += (~url.indexOf('?') ? '&': '?') + 'callback=Callbacks["'+_Fname+'"]';
Callbacks[_Fname] = function(data) {
performed = true;
delete Callbacks[_Fname];
callback(false, data);
script.parentNode.removeChild(script);
};
function onScriptLoad () {
if(performed)
return;
delete Callbacks[_Fname];
callback(true);
script.parentNode.removeChild(script);
}
var script = document.createElement('script');
script.onload = script.onerror = onScriptLoad;
script.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded'){
this.onreadystatechange = null;
setTimeout(onScriptLoad, 0);
}
}