【问题标题】:Get JSON data into TVML prohect without JQuery在没有 JQuery 的情况下将 JSON 数据导入 TVML prohect
【发布时间】:2016-04-10 16:02:50
【问题描述】:

我有一个工作代码可以从 JSON 中获取数据并将其与 JQuery 一起使用。 我可以不使用 JQuery 吗?我该怎么做?

 function performRequest(type, route, data) {
        return $.ajax({
            type: type,
            dataType: 'json',
            url:  '...' + route,
            data: data
        });
    }

    function getChannels() {
        log(' > get channels');
        return performRequest('GET', 'channel/list', {id: browserId}).then(function (response) {
            response.data.forEach(function (channel) {
                channels[channel.id] = channel;
            });
        });
    }

【问题讨论】:

    标签: javascript jquery json tvos tvjs


    【解决方案1】:

    使用 XMLHttpRequest?像这样 - 适用于 aTV2/3...

    var req = new XMLHttpRequest();
    req.onreadystatechange = function()
    {
        if (req.readyState==4)  // 4: request is complete
        {
            data = JSON.parse(req.responseText);
        }
    };
    req.open('GET', url, true);  // true: asynchronous
    req.send();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-21
      • 2017-06-03
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-26
      相关资源
      最近更新 更多