Windows 8的HTML 5 Web应用程序的AJAX后不工作 [英] Windows 8 HTML 5 Web APP AJAX post not working

查看:72
本文介绍了Windows 8的HTML 5 Web应用程序的AJAX后不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

原因:

 不受访问控制 - 允许 - 产地允许的。
 

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

这篇关于Windows 8的HTML 5 Web应用程序的AJAX后不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆