0

I'm working on a widget for my gear S3 running wearable 3.0 that needs to download json data from a server via the internet. It occurs to me that I've made one assumption that may not be correct. That assumption is that since my watch has an LTE radio that it should be able to access the internet and grab the data. Is this possible?

If it is possible I have another question. The following code worked running in chrome:

index.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <script src="js/main.js"></script>
  <style></style>
</head>

<body>
  <div id="page">
    <div id="container">
      <p id="content-text">sucks</p>
      <p> <div>Calories In</div> <div id="calIn">nothing yet</div></p>
    </div>
  </div>
</body>

<script>
console.log("YYY Starting JSON");


fetch('http://my.url').then(response => {
  return response.json();
}).then(data => {
  // Work with JSON data here
  console.log(data);
  //var obj = JSON.parse(data);
  console.log(data.caloriesIn);
  document.getElementById("calIn").textContent = data.caloriesIn;

}).catch(err => {
  // Do something for an error here
});





    </script>

</html>

When I ran this code in Tizen studio I receive this error:

console.error: SyntaxError: Unexpected Punctuator '=>'. Expect','

The json data is 3 or 4 fields that I would like to display as a widget. Can anyone help me fix the code I've started or help me find a way to get this to work?

Loren Zimmer
  • 482
  • 1
  • 6
  • 29

1 Answers1

1

Seems the Compiler/IDE can't recognize the '=>' sign in fetch. Try this format :

fetch('./api/some.json')
  .then(
    function(response) {
    }
  )
  .catch(function(e) {
  });

If you still face Issues, try the XMLHttpRequest instead. Tizen has documentations for XMLHttpRequest.

In addition to Use Internet and to access remote resource you would need to add required privilege and policy, Check out this response .

Md. Armaan-Ul-Islam
  • 2,154
  • 2
  • 16
  • 20