consuming API JSon calls through TVJS-tvOS

前端 未结 6 710
终归单人心
终归单人心 2021-02-06 10:32

I am trying to play with tvOS, and I have small question regarding handling json call. I have to get some data through an API, let\'s say for sake of test that I am calling this

6条回答
  •  一整个雨季
    2021-02-06 10:51

    You need to implement the onreadystatechange event on the XHR object to handle the response:

    templateXHR.onreadystatechange = function() {
      var status;
      var data;
      if (templateXHR.readyState == 4) { //request finished and response is ready
        status = templateXHR.status;
        if (status == 200) {
          data = JSON.parse(templateXHR.responseText);
          // pass the data to a handler
        } else {
          // handle the error
        }
      }
    };
    

提交回复
热议问题