Last active
December 17, 2015 19:19
-
-
Save bmizerany/5659976 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function ajax(m, url) { | |
var r = new XMLHttpRequest(); | |
r.open(m, url); | |
r.header = r.setRequestHeader; | |
r.basicAuth = function() { | |
var s = Array.prototype.slice.call(arguments).join(":"); | |
r.header("Authorization", "Basic " + btoa(s)); | |
} | |
return r; | |
} |
This file contains hidden or 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
var r = ajax("GET", "/topic/" + st.room + "?since=" + st.since); | |
r.basicAuth(store["sid"]); | |
function err(e) { | |
console.debug("poll: ERROR: ", e); | |
} | |
r.addEventLisetner("error", err); | |
r.addEventLisetner("load", function() { | |
switch (r.status) { | |
case 200: | |
doSuccess(); | |
case 401: | |
showLogin(); | |
break; | |
case 404: | |
alert("not found!"); | |
break; | |
default: | |
err(); | |
break; | |
} | |
}); | |
r.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment