[PDB Tech] Access-Control-Allow-Origin

Martin J. Levy mahtin at mahtin.com
Wed Jan 11 11:16:53 PST 2017


This is a JSONP issue (well worth a search on stackoverflow). Once you
master that there are no XSS errors. I also means you don't need the server
to enabled "allow origin". I had some code that works as-is.

      var url = peeringdb_api_url + '/' + $scope.getJSONParam1 + '/' +
$scope.getJSONParam2;
      url = url + '?callback=JSON_CALLBACK';
      console.log('url = "' + url + '"');
      $http.jsonp(url, config)
        .then(function successCallback(response) {
          console.log('successCallback() called');
          $scope.getCallJSONResult = logResult("GET SUCCESS",
response.data, response.status, response.statusText, response.headers,
response.config);
        }, function errorCallback(response) {
          console.log('errorCallback() called');
          $scope.getCallJSONResult = logResult("GET ERROR",
response.data, response.status, response.statusText, response.headers,
response.config);
        });
    };

This is in Angular - but that's a whole other conversation.

Try that.

Martin

On Wed, Jan 11, 2017 at 11:00 AM, Ruairi Carroll <ruairi.carroll at gmail.com>
wrote:

> Hey,
>
> While writing a JS app, I noticed that Access-Control-Allow-Origin is not
> set on api.peeringdb.com.  I also see that there's an open issue for this
> ( https://github.com/peeringdb/peeringdb/issues/78 ).
>
> I was wondering what would be the best way to do this - should I sync and
> host my own copy of the API, or are you OK with having random calls to the
> API from webapps?
>
> /Ruairi
>
> _______________________________________________
> Pdb-tech mailing list
> Pdb-tech at lists.peeringdb.com
> http://lists.peeringdb.com/cgi-bin/mailman/listinfo/pdb-tech
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.peeringdb.com/pipermail/pdb-tech/attachments/20170111/52326c33/attachment.html>


More information about the Pdb-tech mailing list