Soultion1
if you have php on your server create a file called weather.php width this code on the same domain as your page.
<?php
echo file_get_contents('http://api.openweathermap.org/data/2.5/weather?q='.$_GET['q']);
?>
and call it with your function
url:"weather.php?q=London",
Note: slow but real ajax
Soultion2
if openweathermap.org has support for callbacks you can use jsonp
Note: fills the page with <srcip></script>
tags.
Soultion3
use a nodejs proxy
Note: fast & real ajax
Soultion4
using a yql query.
Note: fastest & real ajax
if you need more details just ask
EDIT
Solution5
A Fast way to passtrough the content with php
<?php
function w($ch,$chunk){
echo $chunk;
ob_flush();
flush();
return strlen($chunk);
};
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$_GET['url']);
curl_setopt($ch,CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch,CURLOPT_WRITEFUNCTION,w);
curl_exec($ch);
curl_close($ch);
?>
Note: faster than file_get_contents
& real ajax
by removing the
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
part it's even faster.
EDIT3
proxy's are always a bad idea vs direct as you read the data always 2 times.
direct action
ask->read->display
proxy action
ask->(php/node ask)->(php/node read)->(php/node display)->read->display
but in your case there is no other way to get the data directly.
i tagged the yql as fastest based on average hosts.
most of the data from important sites like openweathermap is probably already cached on the yahoo servers and the their bandwith is very high worldwide (and crossorigin is allowed).
so if you have a slow host that needs to read the data from openweathermap with php or nodejs & then output having a limited bandwidth it's 99% slower than on yahoo's server.
nodejs is faster than php because if you create o good dedicated proxy script you store your data directly inside the system memory. Caching data inside the memory is faster than anything else i know.probaly it's even faster then reading a static file.
the point is how fast your host outputs the request.