2

I was trying to use $http.get. The page only works if the url I give is a local 'vehicles.json' But when I give a url, it spits out a blank page. Could someone please help me understand my error?

5
  • 2
    Open console and fix errors. Then use jsonp method of $http. Commented Aug 12, 2015 at 6:28
  • looks like CORS issue Commented Aug 12, 2015 at 6:33
  • @dfsq The url to the server doesn't have a jsonp callback. Should I still try to use jsonp method instead of $http? Commented Aug 12, 2015 at 14:41
  • @MartinScore you could go for jsonp request Commented Aug 12, 2015 at 14:55
  • Why are you then use &format=jsonp? Anyway this is what you need to do: If (API supports JSONP?) { use JSONP } else if (CORS supported?) { use GET JSON(API url) } else { create server side proxy and GET JSON(proxy url) }. Commented Aug 12, 2015 at 15:03

1 Answer 1

1

You have to replace this line:

 $scope.vehicle = data.['get_vehicles'];

for this:

$scope.vehicle = data['get_vehicles'];

If you modify this in your Plunker, will work.

I hope this solves your question.

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

1 Comment

Did you check if the proglem is CORS? to check it you can open the console (F12 in Chrome) and look at if appear some message saying something like "XMLHttpRequest cannot load domain.example. Origin domain.example is not allowed by Access-Control-Allow-Origin." If your problem is this, you can transform your chrome with disable security (stackoverflow.com/questions/3102819/…)

Your Answer

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