0

ギア 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 Web エミュレーターでエミュレートすると、これは完全に機能します。

しかし、これをギア s2 自体にインストールすると、Web サーバーは要求を受け取りません。config.xml ファイルで、アプリにインターネット権限と Web サーバーへのアクセス権を付与しました。

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

しかし、成功しません。私が何を忘れているのか誰か教えてもらえますか? ありがとう!

4

1 に答える 1

3

コードが他のドメインからアクセスしていないことを確認してください。

他のドメインからアクセスしている場合は、config.xml のアクセス元を次のように変更する必要があります。

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

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

于 2015-12-18T16:39:32.327 に答える