1

我是 Javascript 的超级新手...

如何在不使用 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();
4

2 回答 2

1

jQuery is heavily tied into a DOM, so you might want to look at removing the dependancy on it.

That said, there is a jQuery package in npm so you can run it via node.js on the command line.

于 2013-04-08T18:15:24.443 回答
0

You can try node.js. As far as I know you can install jquery like;

npm install jquery

于 2013-04-08T18:14:35.357 回答