Javascript äquivalent für curl-Befehl

Ich bin mit unter den curl-Befehl, um die Daten von Druide cluster gehostet werden, auf entfernten server, in das json-format

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"]}'

aber ich bin nicht in der Lage erstellen einer entsprechenden javascript-Methode, die das gleiche tun, ich benutze folgenden code, um dies zu tun.

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");
     }
   });
}

Jede Hilfe wird geschätzt.

  • was ist die Fehlermeldung? gibt es eine? Ich vermute ein problem mit CORS/cross-origin...
  • auch, contentType sollte 'application/json' im JS-Teil
InformationsquelleAutor amol-jore | 2013-08-27
Schreibe einen Kommentar