gpt4 book ai didi

ios - 如何在 TVML 应用程序中使用 AJAX 请求?

转载 作者:行者123 更新时间:2023-11-28 17:50:54 26 4
gpt4 key购买 nike

我的浏览器中有一个有效的 AJAX 请求。现在我需要在 TVML 项目中对我的 JSON 数据使用 GET 请求。怎么做比较好?

我正在尝试 XMLHttpRequest,但它不起作用或者我做错了什么?

function performRequest(type, route, data) {
return $.ajax({
type: type,
dataType: 'json',
url: 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;
});
});
}

最佳答案

在我看来,您的代码使用的是 jquery,而不是 XMLHTTPRequest。就个人而言,我没有成功地使用 TVJS 运行 jquery,因为它对 TVJS 不满足的 Document 类做了一些假设。我没有详分割析这个问题,也许你可以找到一些解决方法。

如果您想使用 native XMLHTTPRequest 下载 JSON 资源,请尝试如下操作:

/**
* Downloads a JSON resource
*
* @param {Object} options The options parameter.
* @param {string} options.resourcePath Path to the JSON
* @param {Function} options.success On success, will be called with the resulting JSON object
* @param {Function} [options.error] Error callback
*/
getJSON(options) {

var resourceXHR = new XMLHttpRequest();
resourceXHR.responseType = "json";
resourceXHR.addEventListener("load", (function () {
options.success(resourceXHR.response);
}));
resourceXHR.addEventListener("error", (function () {
options.error({status: resourceXHR.status, statusText: resourceXHR.statusText});
}));
resourceXHR.open("GET", options.resourcePath, true);
resourceXHR.send();
}

关于ios - 如何在 TVML 应用程序中使用 AJAX 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123304/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com