【问题标题】:How to enable http request / internet acces on samsung gear s2如何在三星 Gear s2 上启用 http 请求/互联网访问
【发布时间】:2015-12-18 01:25:48
【问题描述】:

我正在为 gear s2 (javascript) 的 web 应用程序上的切换按钮发送 http 请求:

( function () {

    var led001Button = document.getElementById("Led001"),
        led002Button = document.getElementById("Led002");   

    function httpReq(theUrl){
        var xmlhttp = null;
        xmlhttp = new XMLHttpRequest();
//      xmlhttp.onreadystatechange = function(){
//      if (xmlhttp.readyState == xmlhttp.DONE){
//      alert(xmlhttp.responseText);
//      }
//      else{
//      alert(xmlhttp.statusText);
//      }
//      };
//      xmlhttp.onerror = function(e){
//      alert("onerror: " + xmlhttp.statusText);
//      };
        xmlhttp.open("GET", theUrl);
        xmlhttp.send();
    }

    function checkToggle(name){
            //make box2 = box1 when checked              
               var checkbox = document.getElementById(name);
               if (checkbox.checked === true){
                   httpReq('http://school.thomashuster.nl/WebServer/edit.php?name='+name+'&value=1');
//                console.log("set "+name+" ON");
               }else{
                   httpReq('http://school.thomashuster.nl/WebServer/edit.php?name='+name+'&value=0');
//                 console.log("set "+name+" OFF");
               }
    }           
    if (led001Button) {
        led001Button.addEventListener("change", function(){
               checkToggle("Led001");
        });
    }
    if (led002Button) {
        console.log('test');
        led002Button.addEventListener("change", function(){
               checkToggle("Led002");
        });
    }
} () );

当我在 gear s2 网络模拟器上模拟它时,它可以完美运行。

但是当我在 gear s2 上安装它时,我的网络服务器没有收到任何请求。我在 config.xml 文件中为我的应用授予了 Internet 权限和访问我的网络服务器的权限:

<access origin="https://www.thomashuster.nl" subdomains="true"></access>
 <tizen:privilege name="http://tizen.org/privilege/internet"/>    

但没有成功。谁能告诉我我忘记了什么?谢谢!

【问题讨论】:

  • 您确定您的代码没有从任何其他域访问吗?您可以尝试将 config.xml 中的访问源修改为
  • 请将其标记为答案。

标签: javascript httprequest tizen tizen-wearable-sdk tizen-web-app


【解决方案1】:

您确定您的代码没有从任何其他域访问吗?

如果是从其他域访问,则需要将config.xml中的访问源修改为

&lt;access origin="*" subdomains="true"&gt;&lt;/access&gt;

&lt;access origin="*" subdomains="true"/&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多