gpt4 book ai didi

javascript - XMLHttpRequest 无法加载

转载 作者:行者123 更新时间:2023-11-30 08:32:10 26 4
gpt4 key购买 nike

需要帮助解决这个问题。我们尝试了很多不同的方法,但由于某种原因,访问控制不允许来源错误在尝试访问 keen 时不断弹出

无法加载资源:服务器响应状态为 404(未找到)admin:1 XMLHttpRequest 无法加载 https://api.keen.io/3.0/projects//查询/。预检响应具有无效的 HTTP 状态代码 404

这是 admin.js 中的代码

<script type="text/javascript">
var client = new Keen({
projectId: "id", // String (required always)
writeKey: "key", // String (required for sending)
readKey: "key", // String (required for querying)

// protocol: "https", // String (optional: https | http | auto)
// host: "api.keen.io/3.0", // String (optional)
requestType: "jsonp" // String (optional: jsonp, xhr, beacon)
});
Keen.ready(function() {
var metric = new Keen.Query("newBusiness", {
analysisType: "count",
timeframe: "this_1_month"
});

client.draw(metric, document.getElementById("newBusiness-count-chart"), {
chartType: "metric",
label: "Count of Businesses"
});
});

这些是标题和来源

app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', 'https://api.keen.io:443, fonts.googleapis.com');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Origin, X-Requested-With, Accept');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-withCredentials', true);
next();

});

最佳答案

上面的配置存在一些问题。试一试:

var client = new Keen({
projectId: "id",
writeKey: "key",
readKey: "key",
requestType: "jsonp"
});

Keen.ready(function() {
var metric = new Keen.Query("count", {
eventCollection: "newBusiness", // assuming this is the collection name?
timeframe: "this_1_month"
});
client.draw(metric, document.getElementById("newBusiness-count-chart"), {
chartType: "metric",
title: "Count of Businesses"
});
});

关于javascript - XMLHttpRequest 无法加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36072041/

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