原生js的http请求调用写法(获取图片流并生成图片元素到页面)12345678910111213141516var xhr = new XMLHttpRequest(); xhr.open("get", 'http://api.btstu.cn/sjbz/zsy.php', true); xhr.responseType = "blob"; xhr.onload = function() { if (this.status == 200) { debugger var blob = this.response; var img = document.createElement("img"); img.onload = function(e) { window.URL.revokeObjectURL(img.src); }; img.src = window.URL.createObjectURL(blob); document.getElementsByTagName("body")[0].style.backgroundImage = img; } } xhr.send();