php - Can not take json data with angularjs -


http://moviestolike.pe.hu/get_all_products.php

i want take data , print screen in index.html:

  <!doctype html> <html ng-app="todoapp"> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="script.js"></script> <body> <div class="form-group" ng-controller="todocontroller">       <p>movie list page</p>     <br>     <p>click button see movies</p>       <div class="form-group" >         <div class="col-sm-10 col-sm-offset-2">             <button type="submit" class="btn btn-primary" ng-click="count = count + 1" ng-init="count=0">                 <span class="fa fa-check"></span> count list movie</button>             <span>   count: {{count}} </span>             <button type="submit" class="btn btn-primary" ng-click="listmovie()">                 <span class="fa fa-check"></span> list movie</button>         </div>     </div>      <p>the movis want list is:</p>     <p>list :{{list}}</p>        <p>{{listed}}</p>       <p>ss {{tasks}}</p> </div>  </body> </html> 

i doing in angular.js file

    /**  * created caneraydin on 16.03.2016.  */ var app=angular.module('todoapp',[]); app.controller('todocontroller',function($scope,$http){  var urlbase="";   $scope.toggle=true;   $scope.selection = [];   $scope.statuses=['active','completed'];   $scope.priorities=['high','low','medium'];   $http.defaults.headers.post["content-type"] = "application/json";      $scope.addmovie=function(title,actors){         $scope.title="title clicked "+title          $scope.actors="actors clicked "+actors          $scope.added="the movie '"+title+"' actors '"+actors+"' added successfully"     },      $scope.deletemovie=function(id){         $scope.id="id clicked "+id           $scope.deleted="the movie id '"+id+"' deleted successfully"     },      $scope.listmovie=function(list){        $scope.tasks=[];       $scope.list="list clicked"        $scope.list="list+list"+list       $scope.listed="the movies listing:"+list               $http.get( 'http://moviestolike.pe.hu/get_all_products.php').              success(function (data) {               $scope.tasks=data.name      });  };   }) 

inside listmovie cant post data.

i tried change array still same.

http://plnkr.co/edit/5xte6v?p=preview

i changed code according comments continuing. cant show json data.

when make

 function myerror(response) {     $scope.check = response;       });  

i this:

{"data":null,"status":-1,"config":{"method":"get","transformrequest":[null],"transformresponse":[null],"url":"http://moviestolike.pe.hu/get_all_products.php","headers":{"accept":"application/json, text/plain, */*"}},"statustext":""} 

the data call returns doesn't have name property directly.. please change code this

$http.get( 'http://moviestolike.pe.hu/get_all_products.php').             success(function (data) {              $scope.tasks=data.products; });  

and in html can directly view tasks this

<p>ss {{tasks | json}}</p> 

or view each product this

<div ng-repeat="prod in tasks">name: {{prod.name}}</div> 

edit

in plunker, see console, says

xmlhttprequest cannot load http://moviestolike.pe.hu/get_all_products.php. no 'access-control-allow-origin' header present on requested resource. origin 'http://run.plnkr.co' therefore not allowed access. 

this means cors not available on server , can't access you're accessing (same goes plunkr)

you need enable cors on backend.

you can on link probably: https://remysharp.com/2011/04/21/getting-cors-working


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -