使用amCharts V4,如何在内置API请求中包含cookie?
我正在使用https://www.amcharts.com/docs/v4/concepts/data/loading-external-data/中所述的amCharts外部数据加载器,但需要在请求中包含cookie。
与普通Javascript等效的是
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.example.org/api", true);
xhr.withCredentials = true;
我的代码当前为:
let chart = am4core.create('chartdiv', am4charts.XYChart);
chart.cursor = new am4charts.XYCursor();
chart.dataSource.url = "http://www.example.org/api";
amCharts 4中是否有等效的“ withCredentials”?
答案 0 :(得分:2)
是的,有。 dataSource
有一个requestOptions
property,可以在此处完成以下操作:
chart.dataSource.requestOptions.withCredentials = true;
或者如果requestOptions
由于某种原因尚未初始化:
chart.dataSource.requestOptions = {
withCredentials: true
}
(相关参考资料,如果感兴趣的话:
requestOptions
'界面:https://www.amcharts.com/docs/v4/reference/inetrequestoptions/#withCredentials_property)