English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Methode zur Überprüfung der Zugänglichkeit eines angeforderten URLs, Unterstützung der Cross-Domain-Überprüfung

wie folgt:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; Zeichensatz=gb2312" />
  <meta name="keywords" content="js prüfen, ob URL erreichbar ist" />
  <title>js prüfen, ob URL erreichbar ist</title>
</head>
<body>
  <div>Zu überprüfende URL-Adresse: </div>
  <input type="text" style="width:600px;height:30px;font-size:14px;" id="urlText" value="https://www.baidu.com/" />
    <input type="button" value="Überprüfen, ob zugänglich" onclick="getURL()" />
  <br />
  <div id="msg1></div>
  <div id="msg"></div>
  <script type="text/javascript" src="js/jquery-1.10.2javascript"></script>
  <script type="text/javascript">
    function getURL() {
      $("#msg").html("");
      var url = $("#urlText").val();//Angeforderte URL
      var dateTime = disptime();
      var time2 = dateTime.DateTime; 
      $("#msg1").html("Sendzeit: " + time2); 
      $.ajax({
        type: 'get',
        url: url,
        cache: false,
        dataType: "jsonp", //Cross-Domain mit JSONP-Weise 
        processData: false,
        timeout:10000, //Zeitüberschreitung in Millisekunden
        complete: function (data) {
          var dateTime2 = disptime();
          var time22 = dateTime2.DateTime;
          var htmlTxt =[];
          if (data.status==200) {
            htmlTxt.push("Erfolgreich<br/)");
          } else {
            htmlTxt.push("Fehlgeschlagen<br/)");
          }        
          htmlTxt.push("readyState=" + data.readyState + "<br/>status=" + data.status + "<br/>statusText=" + data.statusText + "<br/>Antwortzeit: " + time22);
          var htmlString = htmlTxt.join('');
          $("#msg").html(htmlString);
        }       
      });
    }
    function disptime() {
      var date = new Date();
      var yyyy = date.getFullYear();//Vierstellige Jahreszahl
      var month = date.getMonth() + 1;//Monat 0-11
      var day = date.getDate();//Tag
      var HH = date.getHours();//Stunden
      var minute = date.getMinutes();//Minuten
      var second = date.getSeconds();//Sekunden
      var milliseconds=date.getMilliseconds();//Millisekunden
      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 + " " + milliseconds;
      var timeTxt = yyyy + month + day + HH + minute + second;
      var time = {
        DateTime: time,
        TimeTxt: timeTxt
      }
      return time;
    }
  </script>
</body>
</html> 

Diese Artikel über die Überprüfung der URL-Auf reachbarkeit von JavaScript, die Unterstützung der Cross-Domain-Überprüfungsmethode, die ich allen zur Verfügung gestellt habe, ist alles, was ich Ihnen zur Verfügung stellen kann. Ich hoffe, es kann Ihnen als Referenz dienen und ich hoffe, dass alle uns mehr unterstützen. Der Anruf-Lehrbuch.

Dir gefällt vielleicht