7
我使用curl命令如下摆脱托管远程服务器上德鲁伊集群中的数据,以JSON格式的Javascript等效curl命令
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");
}
});
}
任何帮助将不胜感激。
错误消息是什么?有没有?我怀疑CORS/cross-origin存在问题... – thriqon
另外,contentType应该是JS应用程序中的'application/json' – thriqon