Weather

GRATUITO
Por fyhao | Atualizado 14 days ago | Data
Popularidade

0.1 / 10

Latência

23ms

Nível de serviço

0%

Health Check

N/A

Voltar para todas as discussões

How do I integrate the call on the web page?

Rapid account: Tomjohnson 1492
tomjohnson1492
9 years ago

Can you tell me how to integrate a call to get the weather forecast on a web page?

I have this sample code created. It should just log the payload to the console.
<pre>
<!DOCTYPE html>
<html>
<head>
<script src=“http://code.jquery.com/jquery-2.1.1.min.js”></script>
<meta charset=“utf-8”>
<title>Mashape Query</title>
<script>
function doIt() {
var output = $.ajax({
url: ‘https://simple-weather.p.mashape.com/weatherdata?lat=37.354108&lng=-121.955236’, // The URL to the API. You can get this by clicking on “Show CURL example” from an API profile
type: ‘GET’, // The HTTP Method, can be GET POST PUT DELETE etc
data: {}, // Additional parameters here
dataType: ‘json’,
contentType: ‘text/plain’,
“async”: true,
“crossDomain”: true,
success: function(data) {
//
//Change data.source to data.something , where something is whichever part of the object you want returned.
//To see the whole object you can output it to your browser console using:
console.log(data);
//document.getElementById(“output”).innerHTML = data.source;
},
error: function(err) { alert(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader(“X-Mashape-Authorization”, “WOyzMuE8c9mshcofZaBke3kw7lMtp1HjVGAjsndqIPbU9n2eET”); // Enter here your Mashape key
}
});

}

</script>
</head>
<body>
</pre>

<button onclick="doIt()">Run the request</button>
<div id="output">The API request is:</div>

</body>
</html>
</pre>

When I run it, however, I get this error msg:

<pre>
XMLHttpRequest cannot load https://simple-weather.p.mashape.com/weatherdata?lat=37.354108&lng=-121.955236. The request was redirected to ‘http://web.qxinnet.com/web/script/imgshow/utility/weather/mashape/weatherdata/?lat=37.354108&lng=-121.955236’, which is disallowed for cross-origin requests that require preflight.
</pre>

Something changed with this API within the past month. Previously I could run this code with no issue at all. Can you tell me what changed, and how I run the call to get the payload? Thanks,

Tom
tomjohnson1492@gmail.com

Rapid account: Fyhao
fyhao Commented 9 years ago

Hi, going to reply you with email

Junte-se à discussão - adicione o comentário abaixo:

Efetue login / inscreva-se para postar novos comentários