0

I'm not able to fetch data through angularjs, it shows blank screen on chrome while running it, don't know the issue since I'm a beginner.

<div ng-app="myApp" ng-controller="customersCtrl"> 
  <ul>
    <li ng-repeat="x in names">
      {{Word}}{{names}}
    </li>
  </ul>
  <div class="footer"></div>
</div>

Here is the jsfiddle: demo

Thanks in advance.

Edit:Finally, I got the solution, after trying for couple of hours,needed to get CORS extension from chrome:working demo

6
  • Does the page you request return a JSON response? Commented Dec 4, 2015 at 16:01
  • yes,here is the link which im targetting randomword.setgetgo.com/… Commented Dec 4, 2015 at 16:02
  • Side Note don't use too older version..do upgrade it.. Commented Dec 4, 2015 at 16:06
  • the jsfiddle doesnt work because you're not including angularjs in the html. You need to add it in a script tag Commented Dec 4, 2015 at 16:14
  • i added it i just pasted a part of the code Commented Dec 4, 2015 at 16:18

1 Answer 1

1

'Access-Control-Allow-Origin' - Cross Origin Requests don't seem to be allowed for your resource API

Updating your request you can add an error response in to catch such problems

$http.get("http://randomword.setgetgo.com/get.php")
  .then(function (response) {
    $scope.names = response.data;
    console.log(response);
  },
       function(error){
    console.log('error',error);    
  });

edit: No idea who marked this down but I changed the api call to one which allows cors and made a fiddle to show it working.

dom

<div ng-app="myApp" ng-controller="customersCtrl"> 

    <ul>
      <li ng-repeat="x in names.data">
        {{x.title}}
      </li>
    </ul>
            <div class="footer"></div>
    </div>

Controller

var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
  $http.get("http://jsonplaceholder.typicode.com/posts")
  .then(function (response) {
    console.log(response);
    $scope.names = response;
  }, function(error){
    console.log(error);
  });
});

If your angular app is hosted separately to your API then you will have a little work to allow access.

Sign up to request clarification or add additional context in comments.

6 Comments

Do me a favor and leave a comment for down votes. If I didn't explain something very well it would be nice to know.
Agree with you about the down vote. Reckon your answer is spot on so I'm going to give you an up vote.
thanks a lot this works great definitely " +1" from my side !!! but any idea how to fetch it from randomword.setgetgo.com/get.php
@neelabhsingh the fiddle may not be working because its not hosted on the same domain but if your angular app was hosted @ randomword.setgetgo.com/index.html you should have more luck
okk ! actually I wanted to have a single meaningflu word at a time,yes there is some issue that i'm not able to do it with this one...
|

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.