0

I 'am working in a restful web application that uses symfony2 as backend and angularjs in frontend,my problem is that I should receive json URLs with ajax,this is my code:

 <script>
function PostsCtrlAjax($scope, $http)
{
$http({method: 'POST', url: 'http://localhost/onlinefacturation/web/app_dev.php/clientapi/clients.json'}).success(function(data)
{
$scope.posts = data; // response data 
});
}
</script>
<div ng-repeat="post in posts" >
<ul>
  <li>{{post.id}}</li>
  <li>{{post.nom}}</li>
  <li>{{post.prenom}}</li>
</ul>
</div> 

this is the console error that I get,plus,I didn't get any data in the View:

 WARNING: Tried to load angular more than once.
angular.js:11383 Error: [ng:areq] Argument 'PostsCtrlAjax' is not a function, got undefined
http://errors.angularjs.org/1.3.2/ng/areq?p0=PostsCtrlAjax&p1=not%20aNaNunction%2C%20got%20undefined
    at REGEX_STRING_REGEXP (http://localhost/ProjetWeb/src/vendor/angular/angular.js:80:12)
    at assertArg (http://localhost/ProjetWeb/src/vendor/angular/angular.js:1577:11)
    at assertArgFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:1587:3)
    at http://localhost/ProjetWeb/src/vendor/angular/angular.js:8333:9
    at chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:622:22
    at http://localhost/ProjetWeb/src/vendor/angular/angular.js:7507:34
    at forEach (http://localhost/ProjetWeb/src/vendor/angular/angular.js:347:20)
    at nodeLinkFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:7494:11)
    at compositeLinkFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:6993:13)
    at nodeLinkFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:7632:24)

thanks for help

update: this is the index.html:

html lang="en" data-ng-app="app" >
<head> ...... </head>
<body ng-controller="AppCtrl">
<div class="app" id="app" ng-class="{'app-header-fixed':app.settings.headerFixed, 'app-aside-fixed':app.settings.asideFixed, 'app-aside-folded':app.settings.asideFolded, 'app-aside-dock':app.settings.asideDock, 'container':app.settings.container}" ui-view></div>.........</body></html>

abd this is the file .html in which I want to get data from the json file URL:

<script>function PostsCtrlAjax($scope, $http)
{
$http({method: 'POST', url: 'http://localhost/onlinefacturation/web/app_dev.php/clientapi/clients.json'}).success(function(data)
{
$scope.posts = data; // response data 
});
}
</script>
    <div class="hbox hbox-auto-xs hbox-auto-sm" ng-init="
        app.settings.asideFolded = false; 
        app.settings.asideDock = false;
      "  data-ng-app="app" ng-app>
    <div id="ng-app" ng-app ng-controller="PostsCtrlAjax">
    <div ng-repeat="post in posts" >
        <ul>
          <li>{{post.id}}</li>
          <li>{{post.nom}}</li>
          <li>{{post.prenom}}</li>
        </ul>
        </div>  
        </div></div>
2
  • 1
    Did you defined your controller in html ng-controller="PostsCtrlAjax" Commented Mar 3, 2015 at 17:01
  • @Hareesh I have fellowed this tutoriel and it's supposed to work very well :/ but I steel can't display data Commented Mar 3, 2015 at 17:09

1 Answer 1

1

Try you controller like this

app.controller('PostsCtrlAjax', ['$scope', '$http' ,function($scope,$http) {
   $http({method: 'POST', url: 'http://localhost/onlinefacturation/web/app_dev.php/clientapi/clients.json'})
   .success(function(data){
        $scope.posts = data; // response data 
   });
}]);
Sign up to request clarification or add additional context in comments.

2 Comments

still the same problem,can't get data :(
Still showing Argument 'PostsCtrlAjax' is not a function, got undefined error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.