Ajax请求在Tizen的模拟器中取消,但在浏览器中没有

时间:2015-06-04 08:37:18

标签: javascript jquery ajax tizen tizen-emulator

当我尝试通过webservice联系$.getJSON时,我的tizen模拟器出现错误。

我有一个按钮,当我点击它时,我从webservice获得JSON,就这么简单。在我的计算机浏览器上,这非常有效,但是当我在Tizen的模拟器(齿轮)上将代码作为应用程序运行时,GET方法返回:(已取消) Request cancelled

这是代码(main.js):

$(window).load(function(){document.addEventListener('tizenhwkey', function(e) {
    if(e.keyName == "back")
        tizen.application.getCurrentApplication().exit();
});
$('.button').click(function(){
    callWebService();//Calls webservice
    return false;
});

function callWebService(){
    //Works on desktop's Chrome
    $.getJSON( "https://www.googleapis.com/freebase/v1/text/en/bob_dylan", function( data ) {
          $('#ol_home_products').html(data.result);
        })
        .fail(function( err ) {
            //Never called
            console.log( err );
        });
}
});

我可以在“网络”标签中看到取消错误,但在控制台中没有显示任何内容。 我不知道Tizen齿轮仿真器的问题在哪里,代码在浏览器中完美运行。

感谢。

编辑:这是我的config.xml,特权互联网在这里。

<?xml version="1.0" encoding="UTF-8"?><widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/myApp" version="1.0.0" viewmodes="maximized">
<tizen:application id="jVqvRz7h1V.myApp" package="jVqvRz7h1V" required_version="2.2"/>
<content src="index.html"/>
<feature name="http://tizen.org/feature/screen.size.all"/>
<icon src="icon.png"/>
<name>myApp</name>
<tizen:privilege name="http://tizen.org/privilege/internet"/>

1 个答案:

答案 0 :(得分:1)

我从Tizen开发者论坛获得了解决方案。我没有在config.xml中设置Internet权限和访问域。

这是正确的文件:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/myApp" version="1.0.0" viewmodes="maximized">
    <tizen:application id="jVqvRz7h1V.myApp" package="jVqvRz7h1V" required_version="2.2"/>
    <access origin="*" subdomains="true"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <name>myApp</name>
    <tizen:privilege name="http://tizen.org/privilege/internet"/>
</widget>