2016-11-24 11 views
1

Ich bin ein kompletter Tableau-Neuling, der an dem Tutorial arbeitet. Ich habe eine getJSON() Anfrage gemacht und mein Skript hängt und kehrt nie zurück. Was mache ich falsch? Ich habe den Link in meinem Browser getestet und eine Antwort wird fast sofort zurückgegeben, es ist also kein Geschwindigkeitsproblem.Tableau JSON-Anfrage funktioniert nicht

(function() { 
var myConnector = tableau.makeConnector(); 

myConnector.getSchema = function (schemaCallback) { 
    var cols = [ 
     {id: "mag", alias: "magnitude", dataType: tableau.dataTypeEnum.float}, 
     {id: "title", alias: "title", dataType: tableau.dataTypeEnum.string}, 
     {id: "url", alias: "url", dataType: tableau.dataTypeEnum.string}, 
     {id: "lat", alias: "latitude", columnRole: "dimension", dataType: tableau.dataTypeEnum.float}, 
     {id: "lon", alias: "longitude", columnRole: "dimension", dataType: tableau.dataTypeEnum.float} 
    ]; 

    var tableInfo = { 
     id: "earthquakeFeed", 
     alias: "Significant Earthquakes in the last seven days", 
     columns: cols 
    }; 

    schemaCallback([tableInfo]); 
    //tableau.log("Hello WDC!"); 
}; 

myConnector.getData = function (table, doneCallback) { 
    $.getJSON("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson", function (resp) { 
     var feat = resp.features, 
       tableData = []; 

     // Iterate over the JSON object 
     for (var i = 0, len = feat.length; i < len; i++) { 
      tableData.push({ 
       "id": feat[i].id, 
       "mag": feat[i].properties.mag, 
       "title": feat[i].properties.title, 
       "lon": feat[i].geometry.coordinates[0], 
       "lat": feat[i].geometry.coordinates[1] 
      }); 
     } 

     table.appendRows(tableData); 
     doneCallback(); 
    }); 
}; 


tableau.registerConnector(myConnector); 
$(document).ready(function() { 
    $("#submitButton").click(function() { 
     tableau.connectionName = "Stock Data for "; 
     tableau.connectionData = "tickerSymbol"; 
     tableau.submit(); 
    }); 
});})(); 

Antwort

0

Ich bin ein echter newb; Ich hatte ein CORS-Problem

0

Ich stieß auf das gleiche Problem. Die Ausgabe von npm start erwähnt etwas über einen Proxy-Server, ist aber nicht sehr hilfreich. Das CORS-Problem sollte eher im Vordergrund stehen als in der Fußnote, die Sie ausgraben müssen. Die Lösung besteht darin, localhost: 8889 zu Ihrer jQuery $.getJSON() Anfrage voran zu stellen.

So folgt aus:

"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson"

Wird dies: "http://localhost:8889/earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson"