Skip to content

Commit

Permalink
Checking on Response type
Browse files Browse the repository at this point in the history
Checking on response type so it doesn't load 404 pages and adds a class of loaded.
  • Loading branch information
jermartin77 authored Feb 9, 2017
1 parent 2523d0a commit af852ee
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions js/inline-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ Currently just using this to inject them into the style guide. Pretty experiment
classNames = $this.attr('class');

var ajax = new XMLHttpRequest();
ajax.open("GET", svgUrl, true);
ajax.send();
ajax.onload = function(e) {
var div = document.createElement("div");
$this.replaceWith(ajax.responseText);
$parent.find('svg').attr('class', classNames);
ajax.open("GET", svgUrl, true);
ajax.send();
ajax.onload = function(e) {

//if the status is not 404 do the replacement otherwise do nothing.
if(ajax.status !== 404) {

var $svg = $(ajax.responseText);

$svg.attr('class', classNames + ' loaded');
$this.replaceWith($svg);

}
else {
$this.addClass('not-loaded');
}

}
}
});
};
}( jQuery ));



0 comments on commit af852ee

Please sign in to comment.