I am trying to create a small angular that takes a json file and displays the data on an html page. However I am getting the following error: POST bookmarks/data/bookmarks.json 405 (Method Not Allowed).
Here is my code:
<html lang="en" ng-app="bookmarksApp" id="ng-app">
    <head>
        <link rel="stylesheet" href="css/styles.css" />
    </head>
    <body ng-controller="BookmarkController as bookmarksCtrl">
        <article class="main-content" role="main">
            <section class="row">
                <div class="content">
                    <div class="bookmarks-list">
                        <h1>Christine's Bookmarks</h1>
                        <ul>
                            <li ng-repeat="bookmark in bookmarksCtrl.bookmarks" class="">
                                <h3>{{bookmark.name}}</h3>
                                <a href="{{bookmark.url}}">{{bookmark.url}}</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </section>
        </article>
        <script type="text/javascript" src="scripts/angular.min.js"></script>
        <script type="text/javascript" src="scripts/main.js"></script>
    </body>
</html>
and my angular code:
(function() {
    var app = angular.module('bookmarksApp', []);   
    app.controller('BookmarkController', function($scope, $http) {
        $http({ method: 'POST', url: 'data/bookmarks.json' }).success(function (data) {
            console.log('hello');
            $scope.bookmarks = data; // response data 
        }).
        error(function (data) {
            console.log(data);
        });
    });
})();
Any ideas where I am going wrong? Thanks.
Try to change the POST to GET.
Also fix the problem in ng-repeat
use
<li ng-repeat="bookmark in bookmarks" class="">
at the place of
<li ng-repeat="bookmark in bookmarksCtrl.bookmarks" class="">
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With