< >

wetter-daten-api-json.php


Quell Code


<!doctype html>
<html lang="de">
<head>
<title></title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch-jsonp/1.0.6/fetch-jsonp.min.js"></script>
</head>
<body>
<span id="Taupunkt">t</span>

<script>


  var linksrc = "https://api.weatherlink.com/v1/NoaaExt.json?user=001D0A00DE6A&pass=DEMO&apiToken=demo0a002bc5272033001d0a002bc527?format=jsonp&callback=DisplayTaupunkt";



fetchJsonp(linksrc)
  .then(res => res.json())
  .then(json => console.log(json));





$.ajax({
  method: 'POST',
  url: linksrc,
      headers: {
      'Host':'https://api-weatherlink.com',
      'authority':'api.weatherlink.com',
        'Content-Type': 'application/jsonp'//'x-www-form-urlencoded'
    },
  dataType: 'jsonp', //change the datatype to 'jsonp' works in most cases
  success: (res) => {
   console.log(res);
  }
})
















$.ajax({
    url: linksrc,
    headers: {
        'Content-Type': 'text/html'//'application/jsonp'//'x-www-form-urlencoded'
    },
    type: "POST",  
    dataType: "jsonp",
    data: {
    },
    success: function (result) {
        console.log(result);    
    },
    error: function () {
        console.log("error");
    }
});




/*




















/*
 window.onload = function () {

  let xhr = new XMLHttpRequest (); 
  xhr.onreadystatechange = function () { 
    if (this.readyState === 4 && this.status === 200) { 
      let response = JSON.parse (this.responseText); 
       document.getElementById('Taupunkt').innerHTML+='Wind dir'+response.wind_dir+' <br>';
       document.getElementById('Taupunkt').innerHTML+='Wind chill C'+response.windchill_c+' <br>';
      
      } 
  } 
  xhr.open ("GET", linksrc); 
  
  //xhr.open ("GET", "https://cors-anywhere.herokuapp.com/"+linksrc);
  xhr.open ("GET", linksrc);
  xhr.setRequestHeader ("Accept", 'application / json'); 
  //xhr.setRequestHeader ("Origin", 'api.weatherlink.com');
  xhr.send (); 

 
 var loadJSONP = (function(){
  var unique = 0;
  return function(linksrc, callback, context) {
    // INIT
    var name = "_jsonp_" + unique++;
    //if (linksrc.match(/\?/)) url += "&callback="+name;
    //else 
    linksrc += "?callback="+name;
    
    // Create script
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = linksrc;
    
    // Setup handler
    window[name] = function(data){
      callback.call((context || window), data);
      document.getElementsByTagName('head')[0].removeChild(script);
      script = null;
      delete window[name];
    };
    
    // Load JSON
    document.getElementsByTagName('head')[0].appendChild(script);
  };
})();
 loadJSONP();
 
 
 $.ajax({
    type: "POST",
    url: linksrc,
    data: 1,
        mode: 'cors',
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Accept': 'application/json',
        'Content-Type': 'application/json',
    },
    success: data=>{console.log(data)},
    dataType: 'json',
});
 
 

 
  $.getJSON(linksrc, function(data) {
      method: 'POST',
    mode: 'cors',
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Accept': 'application/json',
        'Content-Type': 'application/json',
    },
  
  
  
        console.log(data);
		if (data.query.results === 'null'){ 
            $('#error').html('Error beim Laden');
        }else{
               $('#Taupunkt').html(data.query);
        }
  
 });
 
}
*/
</script>
</body>
</html>