mallowigi
1/18/2017 - 8:39 AM

download image

download image

APP.getImage = function() {
    var r = new XMLHttpRequest();

    r.open('GET', 'https://source.unsplash.com/category/nature/100x100', true);
    r.responseType = 'arraybuffer';

    r.onreadystatechange = function(){
		if(this.readyState === XMLHttpRequest.DONE){

			if (this.status === 200) {

				var blb = new Blob( [this.response] , {type : 'image/jpeg'} ),
					reader = new FileReader();


				reader.addEventListener("load", function() {

					var dataurl = this.result;
					APP.setImage(dataurl);

				}, false);

				reader.readAsDataURL(blb);
			}
		}
	};
	r.send();

};