user2331095
user2331095

Reputation: 6727

angular - can't get data with $http

I build my angularjs app with Grunt and yeoman.

My host in example.com and my api is example.com/api

Then I try to use $http like:

$http.get('/api/posts').success(function (data) {
    console.log(data)    //the data is my index.html code
})

Can anyone tell me why the data I get is my index.html code ? And How can I fix it ?

Thanks!

Upvotes: 0

Views: 95

Answers (1)

icanbeacoder
icanbeacoder

Reputation: 1388

You get the index.html code back when you try to access the page ('/api/posts') that does not exist or cannot be accessed directly, try seeing

example.com/api/posts/

on browser address bar and see what it returns.

Upvotes: 2

Related Questions