Skip to content

Instantly share code, notes, and snippets.

@saxap
Created August 30, 2015 18:34
Show Gist options
  • Save saxap/4700f07d01e9c9c009d9 to your computer and use it in GitHub Desktop.
Save saxap/4700f07d01e9c9c009d9 to your computer and use it in GitHub Desktop.
some functions..
var is_ajaxed = false;
$.ajaxSetup({
//async: false
});
$(document).ajaxSend(function() {
console.log( "is_ajaxed." );
is_ajaxed = true;
});
$(document).ajaxStop(function() {
console.log( "last is complete." );
is_ajaxed = false;
});
var queue;
var i = 0;
queue = function() {
return new Promise(function(resolve, reject) {
console.log(i);
i++;
if (i > 3) {
resolve(1);
} else {
setTimeout(function(){
queue().then(function(){
resolve(1);
});
}, 2000);
}
});
}
function wait() {
return queue().then(function(aar){
i = 0;
});
}
//usage
wait().then(function(){
console.log('done');
console.log('blabla');
wait().then(function(){
console.log('done2');
});
});
var i = 0;
function wait2(res) {
i++;
console.log(i);
setTimeout(function(){
if (i>3) res('wdwdwd');
else wait2(res);
}, 2000);
}
wait2(function(res){alert(res);});
function file_get_contents( url ) {
return new Promise(function(resolve, reject) {
var req = null;
try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
try { req = new XMLHttpRequest(); } catch(e) {}
}
}
if (req == null) throw new Error('XMLHttpRequest not supported');
req.open("POST", url, false);
req.send(null);
resolve(req.responseText);
});
}
file_get_contents('url.me').then(function(txt){ alert(txt) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment