As shown below:
<html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta name="keywords" content="js determine whether the URL is accessible" /> <title>js determine whether the URL is accessible</title></head><body> <div>The URL address of the verification: </div> <input type="text" id="urlText" value="https://www.baidu.com/" /> <input type="button" value="json whether it is accessible" onclick="getURL()" /> <br /> <div id="msg1"></div> <div id="msg"></div> <script type="text/javascript" src="js/jquery-1.10.2.js"></script> <script type="text/javascript"> function getURL() { $("#msg").html(""); var url = $("#urlText").val();//Requested url var dateTime = disptime(); var time2 = dateTime.DateTime; $("#msg1").html("Send time:" + time2); $.ajax({ type: 'get', url: url, cache: false, dataType: "jsonp", //JSYNLOGICAL JSONP method is used to processData: false, timeout:10000, //Timeout time, milliseconds complete: function (data) { var dateTime2 = disptime(); var time22 = dateTime2.DateTime; var htmlTxt =[]; if (data.status==200) { htmlTxt.push("Success<br/>"); } else { htmlTxt.push("Failed<br/>"); } htmlTxt.push("readyState=" + data.readyState + "<br/>status=" + data.status + "<br/>statusText=" + data.statusText + "<br/>Response time: " + time22); var htmlString = htmlTxt.join(''); $("#msg").html(htmlString); } }); } function disptime() { var date = new Date(); var yyyy = date.getFullYear();//Four-bit year var month = date.getMonth() + 1;//Month 0-11 var day = date.getDate();//day var HH = date.getHours();//time var minute = date.getMinutes();//minute var second = date.getSeconds();//second var milliseconds=date.getMilliseconds();//ms if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } if (HH < 10) { HH = "0" + HH; } if (minute < 10) { minute = "0" + minute; } if (second < 10) { second = "0" + second; } var time = yyyy + "-" + month + "-" + day + " " + HH + ":" + minute + ":" + second + " " + millionseconds; var timeTxt = yyyy + month + day + HH + minute + second; var time = { DateTime: time, TimeTxt: timeTxt } return time; } </script></body></html>The above article JS determines whether the requested url is accessible. The implementation method that supports cross-domain judgment is all the content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.