gpt4 book ai didi

javascript - xhr 未定义 | Mithril js

转载 作者:太空宇宙 更新时间:2023-11-04 16:30:06 25 4
gpt4 key购买 nike

我最近开始尝试 Mithril js,并偶然发现了随请求一起发送一些授权和其他 header 的基本要求。在阅读了在线文档和一些示例后,我明白这是可以做到的 -

m.request({
method: "GET"
url: "/some/url/"
config: function(xhr) {
xhr.setRequestHeader("Authorization", "".concat("Token ", API_TOKEN));
}
});

我的问题是 xhr 被传递到哪里?因为这显然会出现错误:Uncaught ReferenceError: xhr is not Defined

我无法设置标题。如果我必须声明 XMLHTTPRequest 实例并在那里使用 open() ,那么需要 m.request() 吗?

我做错了什么?方向会有所帮助。

最佳答案

只要 config 钩子(Hook)为您提供 xhr 对象作为第一个参数,这应该可以正常工作。 It is, according to the documentation

但是我确实注意到一些语法错误(缺少逗号)。这解决了吗?

m.request({
method: "GET",
url: "/some/url/",
config: function(xhr) {
xhr.setRequestHeader("Authorization", "".concat("Token ", API_TOKEN));
}
});

关于javascript - xhr 未定义 | Mithril js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39886953/

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