javascript - Find the HTTP status code of an image at `onload` event -


this question has answer here:

suppose following code:

var img = new image(1, 1); img.onload = function() {     console.log(arguments); }; img.src = 'some.place.com/some/image.jpg'; 

when image load, print arguments, contains event object, information request event, can't find anywhere status code.

the firing of onload event doesn't distinguish between direct successful request or successful else redirect.

i need distinguish in code if request direct or redirect, can't find out how without http status code. there somewhere information available?

it's not possible http status of request made image element in javascript, you'd need use ajax loader in order access information this.

alternately, can use img.complete:

htmlimageelement.complete returns boolean true if browser has fetched image, , in supported image type decoded without errors.1


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -