-2

I have an input field in which i am asking user to enter the web URL. Now from frontend itself i want to check the HTTP status codes of the URL entered.

Is it possible using jquery or javascript ? Any help is appreciated ;)

HOW MY QUESTION IS DIFFERENT ?

I wants to get status code from URL, not a ping from IP.

b0y
  • 526
  • 7
  • 22
  • 1
    Possible duplicate of http://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-server-from-javascript – Krishnakant Jun 09 '16 at 10:19
  • 1
    @Krishnakant I think it's not a duplicate, since he wants to get status code from URL, not a ping from IP – Marcin O Jun 09 '16 at 10:26

1 Answers1

1

For pages which allow cross-site scripting (XSS) (e.g. allow-control-allow-origin: * on the server side) you can do it with jQuery easily:

$.ajax({
    url:'https://www.example.com',
    type:'GET'})
    .always(function (jqXHR) {
                console.log(jqXHR.status);
});

But most pages will prevent XSS for good reasons!

oberbics
  • 378
  • 3
  • 11
  • 1
    Isn't this just a normal get? This would result in actually fetching the contents of the page, not just pinging the response code. – Marc Aug 29 '17 at 08:36