javascript - 如何在三星 gear s2 上启用 http 请求/互联网访问

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

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

( 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 文件中授予了我的应用程序互联网权限并访问我的网络服务器:

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

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

最佳答案

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

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

<access origin="*" subdomains="true"></access>

<access origin="*" subdomains="true"/>

关于javascript - 如何在三星 gear s2 上启用 http 请求/互联网访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34347165/

相关文章:

java - 奇怪的 "JSONObject not found"错误

eclipse - 尝试从 Tizen SDK 启动 Tizen watch 应用程序时出现 "Installation or uninstallation is not working temporarily"错误

tizen - 无法通过 Tizen Studio 将应用程序启动到智能电视

java - 在不使用 LinkedMultiValueMap 的情况下将请求正文传递给 Spring Rest 模板

javascript - 使用pdf.js嵌入PDF到网页

javascript - 在正文中使用 javascript 将样式表添加到 Head

javascript - React dropzone 无法使用 axios 发布

java - GWT RequestBuilder - 跨站请求

Tizen 工作室 : Unable to install application due to signature error in certificate profile (Error: -12)

c# - map 初始化后将标记添加到谷歌地图