我正在使用以下 curl 命令以 json 格式从托管在远程服务器上的 Druid 集群获取数据
curl -X POST "http://www.myserverIP.com:8080/druid/v2/" -H 'content-type: application/json' -d '{"queryType": "groupBy","dataSource": "twsample","granularity": "none","dimensions": ["created_at"],"aggregations": [{"type": "count", "name": "tweetcount"}],"intervals": ["2013-08-06T11:30:00.000Z/2020-08-07T11:40:00.000Z"]}'
但我无法创建一个等效的 javascript 方法来做同样的事情,我正在使用下面的代码来做到这一点。
function sendCurlRequest(){
var json_data = {
"queryType": "groupBy",
"dataSource": "twsample",
"granularity": "none",
"dimensions": ["created_at"],
"aggregations": [
{"type": "count", "name": "tweetcount"}
],
"intervals": ["2013-08-06T11:30:00.000Z/2020-08-07T11:40:00.000Z"]
};
$.ajax({
cache : false,
type: 'POST',
crossDomain:true,
url: 'http://www.myserverIP:8080/druid/v2/',
data:json_data,
//dataType: "jsonp",
contentType:"application/jsonp",
success: function(data){
alert(data);
var pubResults = data;
},
error: function(data){
alert("ERROR RESPONSE FROM DRUID SERVER : "+JSON.stringify(data));
},
complete: function(data){
console.log("call completed");
}
});
}
任何帮助将不胜感激。