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