gpt4 book ai didi

javascript - 如何独立于 HTML 运行 Javascript 文件

转载 作者:行者123 更新时间:2023-11-28 02:19:29 25 4
gpt4 key购买 nike

我是 Javascript 的 super 新手...

如何在不使用 HTML 代码的情况下运行 .js 文件?我还需要能够运行 .js 文件中的 JQuery(ajax 命令)。

我正在尝试测试以找出在 Elasticsearch 服务器上运行查询的 Ajax 命令返回的确切内容。

这是我的代码,我想确切地了解正在提取的内容:

var load_data = function() {
$.ajax({ url: 'http://localhost:9200/inventory/_search?pretty=true'
, type: 'POST'
, data :
JSON.stringify(
{
"query" : { "match_all" : {} },

"facets" : {
"tags" : {
"terms" : {
"field" : "qty_onhand",
"size" : "10"
}
}
}
})
, dataType : 'json'
, processData: false
, success: function(json, statusText, xhr) {
return display_chart(json);
}
, error: function(xhr, message, error) {
console.error("Error while loading data from ElasticSearch", message);
throw(error);
}
});
};
load_data();

最佳答案

jQuery 与 DOM 紧密相关,因此您可能需要考虑删除对它的依赖。

也就是说,有 a jQuery package在 npm 中,这样你就可以通过 node.js 运行它在命令行上。

关于javascript - 如何独立于 HTML 运行 Javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15885965/

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