Lieutenant Dan
Lieutenant Dan

Reputation: 8284

nfl data API error

I'm trying to parse a simple amount of data using the NFL data API. Grabbing current season.

EG: http://developer.fantasydata.com/docs/services/300/operations/1114/console

I'm using the sample JavaScript code provided directly on that page with a valid, premium, API key and I'm getting an error dialog. Any one familar?

<!DOCTYPE html> 
<html> 
<head> 
<title>JSSample</title> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
</head> 
<body> 
<script type="text/javascript"> 
    $(function() { 
        var params = { 
            // Specify your developer key 
            key: '1234actualkeyisrighthere', 
        }; 

        $.ajax({ 
            // Specify values for path parameters (shown as {...}) 
            url: 'http://api.nfldata.apiphany.com/premium/XML/CurrentSeason?' + $.param(params), 
            type: 'GET', 
            beforeSend: function (xhr) { 
                debugger; 
            } 
        }) 
        .done(function(data) { 
            alert("success"); 
        }) 
        .fail(function() { 
            alert("error"); 
        }); 
    }); 
</script> 
</body> 
</html> 

Error Details:

It's an error dialog pop-up. 'Error' Console reports: XMLHttpRequest cannot load http://api.nfldata.apiphany.com/premium/XML/CurrentSeason?key=XXXXXXXXXXX. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.sample.com' is therefore not allowed access. currentseason.html:1

Upvotes: 2

Views: 415

Answers (1)

Stephen Thomas
Stephen Thomas

Reputation: 14053

Looks like you're out of luck. The server hasn't enabled cross origin requests (as indicated by the error message). And, at least on my brief rummage through their documentation, they don't seem to support JSONP. You could see if there's undocumented support for JSONP by trying it. You'd have to guess at the callback query string parameter name, though many sites uses callback so that's what I'd try.

OTOH, you probably wouldn't implement this call in a browser anyway, since that would expose your premium API key to any user of your web site. Most likely, the NFL server expects you to proxy the data through your own server. In that architecture, CORS wouldn't be an issue.

Upvotes: 2

Related Questions