refactor XMLHttpRequest to lib.js