Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requirejs jsonp and Uncaught SyntaxError: Unexpected token :

I am testing this JSON feed https://www.unisport.dk/api/sample/ using requirejs jsonp like this

require(['https://www.unisport.dk/api/sample/?callback=define'],
  function ( data ) {
    console.log( typeof data );
  }
);

as it is described here http://requirejs.org/docs/api.html#jsonp. I have used https://jsonformatter.curiousconcept.com/ to verify the feed. But this code snippet throws the following exception

Uncaught SyntaxError: Unexpected token :

My HTML looks like this

<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="css/normalize.min.css">
        <link rel="stylesheet" href="css/main.css">

        <script src="scripts/vendor/modernizr-2.8.3.min.js"></script>
    </head>
    <body>


        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="scripts/vendor/jquery-1.11.2.min.js"><\/script>')</script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.20/require.min.js" data-main="scripts/main"></script>

    </body>
</html>

jQuery is not being used anywhere, there is no other code than whats been posted above.

like image 387
kristian nissen Avatar asked Apr 21 '26 03:04

kristian nissen


1 Answers

JSONP is something that the remote server has to explicitly support, and it looks like the server you're pointing to doesn't.

It's returning plain JSON which, when evaluated as a script, will throw the error you're getting.

like image 71
robertklep Avatar answered Apr 22 '26 15:04

robertklep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!