Can’t get WordPress’ JSON REST API working with JQuery

I’m working my way through freeCodeCamp’s front-end projects, but I’m not having any luck with obtaining quotations using the following code; could anyone point me in the right direction?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Random Quotation Generator</title>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <script>
        $("#getQuotation").on('click', function () {
            $.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&callback=", function (data) {
                $(".message").html(data[0].content + " — " + data[0].title)
            });
        });
    </script>
</head>

<body>
    <div class="container">
        <div class="row text-center">
            <h1 class="text-primary">Random Quotation Generator</h1>
            <div class="well col-xs-12 message">
                <h4>Click the button below to get a nice fresh quotation!</h4>
            </div>
        </div>
        <div class="col-xs-12 row text-center ">
            <button id="getQuotation" class="btn btn-primary">Gimme a quotation!</button>
        </div>
    </div>
</body>

</html>

Read more here: Can’t get WordPress’ JSON REST API working with JQuery

Leave a Reply

Your email address will not be published. Required fields are marked *