How to get the HTTP status code of another site with JavaScript?
I am assuming JavaScript with jQuery, which simplifies AJAX queries like this.
$.ajax({ url: 'url', type: 'GET', complete: function(transport) { doing whatever.. } });
Try the following javascript code snippet:
function getReq() { var req = false; if(window.XMLHttpRequest) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } } else if(window.ActiveXObject) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } } if (! req) { alert("Your browser does not support XMLHttpRequest."); } return req; } var req = getReq(); try { req.open("GET", 'http://www.example.com', false); req.send(""); } catch (e) { success = false; error_msg = "Error: " + e; } alert(req.status);
XMLHTTPRequest HTTP. , HEAD URL-. XMLHTTPRequest - xhr
xhr.open("HEAD", <url>,true); xhr.onreadystatechange=function() { alert("HTTP Status Code:"+xhr.status) } xhr.send(null);
. .
AJAX - .
You will need to configure the proxy service on your server and then make ajax calls with the address you want to check. From your proxy server you can use cURL or which tool you want to check the status code and return it to the client.
Source: https://habr.com/ru/post/1755726/More articles:How to raise reboot class in JBoss - javaHow TFS integrates with SharePoint - tfsСвязывание WPF свойства string и Button.Content - data-bindingНайти подключенных пользователей в Google - javaGql date request - google-app-engineWhat steps can be taken to create a semantic, accessible, standards-compliant client on the client side using ASP.NET Web forms? - javascriptBest primary key format for a large table - c #COM + link with .Net with variable GUID - .netExport and import selected rows in database - importCan I customize the layout to always return the object specified in one of the arguments? - rhino-mocksAll Articles