由网友(爱情就是地狱中的魔咒)分享简介:我创建的Windows Phone 8 5的HTML应用程序。我想阿贾克斯后获取天气信息。但我没有得到任何回应。我无法追踪其背后的问题。 $(文件)。就绪(函数(){VAR apiUrl = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=London...![使用HTML5构建Windows 8应用程序 完成我们的小型RSS阅读器](/d/file/2023/09-16/d5f2e43eb76d5b292ac02149166bd90c.png)
我创建的Windows Phone 8 5的HTML应用程序。我想阿贾克斯后获取天气信息。但我没有得到任何回应。我无法追踪其背后的问题。
$(文件)。就绪(函数(){
VAR apiUrl = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=5&key=KEY GOES HERE;
//回调函数
功能mapWeather(){
$(#的ContentPanel)文本(111)。
$阿贾克斯({
网址:apiUrl,
键入:GET,
成功:功能(数据){
$(#的ContentPanel)文本(adfdf)。
}
});
}
});
HTML
< DIV ID =排液>
< DIV CLASS =输入追加>
<输入类型=文本ID =searchCity/>
&所述按钮类型=链接的id =addCity不可选择=上的类=BTN BTN-主的onclick =mapWeather()&GT +其中; /按钮>
< / DIV>
< DIV ID =的ContentPanel>
测试
< / DIV>
< / DIV>
解决方案
原因:
不受访问控制 - 允许 - 产地允许的。
![使用HTML5构建Windows 8应用程序 完成我们的小型RSS阅读器](/d/file/2023/09-16/d5f2e43eb76d5b292ac02149166bd90c.png)
您正在尝试做AJAX跨域。
修改
的例子,在这里PHP,proxy.php:
&LT ;?
$ URL = $ _ SERVER ['QUERY_STRING'];
从$ = strpos($网址,URL =')+ 4;
$ URL = SUBSTR($网址,$的);
回声utf8_de code(的file_get_contents($ URL));
?>
然后调用阿贾克斯
VAR apiUrl = "proxy.php?url=http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=YOURKEY";
I am creating Windows Phone 8 HTML 5 App. I trying to ajax post for getting weather information. But i am not getting any response. I am unable to trace the problem behind it.
$(document).ready(function () {
var apiUrl = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=5&key=KEY GOES HERE";
//CALL BACK FUNCTION
function mapWeather() {
$("#contentPanel").text("111");
$.ajax({
url: apiUrl,
type: 'GET',
success: function (data) {
$("#contentPanel").text("adfdf");
}
});
}
});
HTML
<div id="row-fluid">
<div class="input-append">
<input type="text" id="searchCity" />
<button type="button" id="addCity" unselectable="on" class="btn btn-primary" onclick="mapWeather()">+</button>
</div>
<div id="contentPanel">
testing
</div>
</div>
解决方案
Reason :
is not allowed by Access-Control-Allow-Origin.
You are trying to do AJAX cross-domain.
EDIT
Example of a, here in php, proxy.php :
<?
$url=$_SERVER['QUERY_STRING'];
$from=strpos($url, 'url=')+4;
$url=substr($url, $from);
echo utf8_decode(file_get_contents($url));
?>
Then you call the ajax as
var apiUrl = "proxy.php?url=http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=YOURKEY";
相关推荐
最新文章