0

I am trying to get data in my table by using jsonp. I really don't know what I am doing wrong. I think it has something to do with the contents of my url. Or that I am not getting the data correctly. I have tried to do callback= JSON_callback. Still does not work.

This is my url http://jbossews-themaopdracht78.rhcloud.com/rest/json/org/JSONP/Organisaties?callback=JSON_CALLBACK

with contents:

callback([{"naam":"Hogeschool InHolland","docenten":null,"id":null},{"naam":"Hogeschool Utrecht","docenten":null,"id":null},{"naam":"Universiteit Utrecht","docenten":null,"id":null}])

app.js:

 angular.module('OrganisatieApp', [
'OrganisatieApp.controllers',
'OrganisatieApp.services'
 ]);

services.js:

  angular.module('OrganisatieApp.services', [])
.factory('organisatieAPIservice', function($resource,$http) {

    var organisatieAPIservice = [];
organisatieAPIservice.getOrganisaties = function(){
    return $http({
        method: 'jsonp',
        url: 'http://jbossews-themaopdracht78.rhcloud.com/rest/json/org/JSONP/Organisaties?callback=callback'
    });

}
        return organisatieAPIservice;
        });

my Html div:

     <div class="panel-body">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>Organisatie naam</th>
                        <th>Organisatie plaats</th>
                        <th>Organisatie Curriculum</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="organisatie in organisatieList">
                        <td>{{$index + 1}}</td>
                        <td>
                            <img src="/img/logos/{{organisatie.Organisatie.logo}}.png" />
                            {{organisatie.Organisatie.naam}}&nbsp;{{organisatie.Organisatie.docenten}}
                        </td>
                        <td>{{organisatie.Constructors[0].provincie}}</td>
                        <td>{{organisatie.curriculum}}</td>
                    </tr>
                    </tbody>
                </table>
                <ng-view></ng-view>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="page-header">
            <h1>Opleidingsprofiel</h1>

        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <ul class="nav nav-pills" role="tablist">
                        <li role="presentation"><a href="#">Aantal Organisaties<span class="badge">3</span></a></li>
                    </ul>
                </h3>
            </div>



            <div class="panel-body">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>Organisatie naam</th>
                        <th>Organisatie plaats</th>
                        <th>Organisatie Curriculum</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="organisatie in organisatieList">
                        <td>{{organisatie.Organisatie.id}}</td>
                        <td>
                            <img src="/img/logos/{{organisatie.Organisatie.logo}}.png" />
                            {{organisatie.Organisatie.naam}}&nbsp;{{organisatie.Organisatie.docenten}}
                        </td>
                        <td>{{organisatie.Constructors[0].naam}}</td>
                        <td>{{organisatie.naam}}</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

controller.js:

       angular.module('OrganisatieApp.controllers', []).
controller('organisatieController',function($scope, organisatieAPIservice) {

    $scope.organisatieList = [];

        organisatieAPIservice.getOrganisaties().success(function (response) {
            //Assign response in Callback
            $scope.organisatieList = response.docenten;
        });
 });
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
user3599415
  • 283
  • 3
  • 6
  • 18
  • [It is clearly mentioned in the documentation that it must be `JSON_CALLBACK`](https://docs.angularjs.org/api/ng/service/$http#jsonp) – PSL May 18 '15 at 16:10

1 Answers1

0

The name of the callback should be "JSON_CALLBACK"

https://docs.angularjs.org/api/ng/service/$http#jsonp

Pierre Gayvallet
  • 2,933
  • 2
  • 23
  • 37