javascript - Status Code 304 -


i new javascript , server-side programming. trying send request load image blog: http://jsafaiyeh.github.io/img/suw_background.png

function imgload(url) { return new promise(function(resolve, reject) {    var request = new xmlhttprequest({mozsystem: true});   request.open('get', url);   request.responsetype='blob';    request.onload = function() {     if (request.status >= 200 && request.status < 400) {       resolve(request.response);     } else {       reject(error('image did\'t load successfully; error code '+ request.statustext));     }   };    request.onerror= function() {     reject(error('there network error'));   };   request.send(); }); }  var body = document.queryselector('body'); var myimage = new image();  imgload('http://jsafaiyeh.github.io/img/suw_background.png').then(function response() {   var imageurl = window.url.createobjecturl(response);   myimage.src = imageurl;   body.appendchild(myimage); }, function(error) {   console.log(error); }); 

i status code 304. however, image still not load onto page. appreciated.

you have wrong function signature. should this:

imgload('http://jsafaiyeh.github.io/img/suw_background.png').then(function (response) {   var imageurl = window.url.createobjecturl(response);   myimage.src = imageurl;   body.appendchild(myimage); }, function(error) {   console.log(error); }); 

working demo on jsfiddle(at least in chrome).

instead of passing named function, called response wanted response in argument list. so, instead of function response(), need function (response). didn't error response undefined, because declared, wasn't expected result promise, function.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -