1 Reply Latest reply on Jul 19, 2017 9:40 AM by patrick.byrne.0

    Help with JSONP connection

    David McClelland

      I'm trying to get a WDC set up, but unfortunately I've run into a CORS problem with downloading my data. I've been trying to use JSONP to get around the issue, but my Javascript skills are pretty rusty (and probably didn't deserve to be called skills in the first place) so I'm pretty unsure of what I'm doing. This is what I have right now:

       

      (function() {

       

         var scriptTag = document.createElement('script');

         scriptTag.src = "http://longurl.com&callback=getWaterData";

         document.getElementsByTagName('head')[0].appendChild(scriptTag);

       

         // Create the connector object

       

         // Define the schema

        


         // Download the data

         var getWaterData = function(jsonpData) {

         alert(jsonpData.someProperty);

        };


         myConnector.getData = function(table, doneCallback) {

         $.getJSON(getWaterData, function(resp) {

         var feat = resp.features,

         tableData = [];


         // Iterate over the JSON object

         for (var i = 0, len = feat.length; i < len; i++) {

         tableData.push({

      // Variables here

        });

        }


         table.appendRows(tableData);

         doneCallback();

        });

        };

           // Register connector and event listeners

        });

      })();

       

      I get a 404 error when I run this, so I'm guessing that I can't simply pass in my getWaterData variable like I'm attempting to do. Any help on how to actually get this set up properly would be appreciated!