Windows 8的HTML 5 Web应用程序的AJAX后不工作应用程序、工作、HTML、Windows

由网友(爱情就是地狱中的魔咒)分享简介:我创建的Windows Phone 8 5的HTML应用程序。我想阿贾克斯后获取天气信息。但我没有得到任何回应。我无法追踪其背后的问题。 $(文件)。就绪(函数(){VAR apiUrl = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=London...

我创建的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

 < D​​IV ID =排液>
        < D​​IV CLASS =输入追加>
            <输入类型=文本ID =searchCity/>
            &所述按钮类型=链接的id =addCity不可选择=上的类=BTN BTN-主的onclick =mapWeather()&GT +其中; /按钮>
        < / DIV>
< D​​IV ID =的ContentPanel>
        测试
    < / DIV>
    < / DIV>
 

解决方案

原因:

 不受访问控制 - 允许 - 产地允许的。
 
使用HTML5构建Windows 8应用程序 完成我们的小型RSS阅读器

您正在尝试做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";

阅读全文

相关推荐

最新文章