0

I am running on domain server1.

I have my RESTful services on server2.

I want to access this RESTful service on my webpage using angularjs. I tried this way. But it's returning an empty array. No data was bind. Why? any suggestions. Here is my sample code.

anilCSE
  • 2,461
  • 3
  • 23
  • 29

2 Answers2

0

In your sample code, your resource definition looks like this:

var UtilService = $resource('server2/users/:userId', { },
    {
        'get' : { method: 'GET',headers: {'Content-Type':'application/json'}, params: { userId:'anil' } , isArray : true }
    }
)

That URL appears to be relative. If you're trying to target a remote server, you're going to need a resolvable URI. Unless that's something that was mangled in the anonymizing of your example, I think that's your issue.

S McCrohan
  • 6,663
  • 1
  • 30
  • 39
  • Thank you for that. Thats not a relative URL, I am providing the actual url there. There I am running my server1 on localhost:8000 and server2 on localhost:3000. – anilCSE May 09 '13 at 14:50
  • Pardon the question, but...you have submitted this request manually to server2 and verified that it returns good results when the Angular front end is taken out of the loop? – S McCrohan May 09 '13 at 15:18
  • If I try the same URL manually, I am getting the service results. But unable to get in this method? – anilCSE May 09 '13 at 16:52
0

You're having a similar problem to me I think. It looks like a SOP (same origin policy) issue. You can't access a different port on the local host without using JSONP or CORS. (I've got a question open with how to do this using CORS at the moment but there are plenty of docs available on the net for JSONP). see also this question

Hope this helps.

Community
  • 1
  • 1
David Swindells
  • 641
  • 1
  • 12
  • 28