I am learning angularJS and trying to implement it in my application.
I have an RESTful WCF service hosted on localhost IIS. It has a GET method defined to fetch a l
I could resolve this issue. Couple of ways to do so - I am jotting down all that i have tried and their references.
Answer to Ques1.
'Why is localhost or my machineName considered to be a cross-domain request?'
as @charlietfl mentioned and i Researched here: a different port or subdomain is also consider cross domain by browser.
Answer to Ques2.
'Are there any changes required to do at my service end to enable this behavior?'
YES! the change is required on server end itself. The server should respond to the request with
Access-Control-Allow-Origin: *
header. Here the * could be replaced with the request header itself or as per your application requirement. Excellent blog here explaining the workaround if you're using WCF REST Service. You need to add following line (headers) to each your service method to enable CORS in your service methods.
WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Methods", "POST"); WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Headers", "Content-Type, Accept");
A specification here is very helpful for enabling CORS on server / client.
Answer to Ques3.
JSONP mostly works for GET requests and aren't most advisable use ,rather enabling CORS is most recommended. (I haven't explored this area much but Wiki & stackoverflow article here were very descriptive).
Apart from that, for testing purpose, a nice chrome extension here can be helpful. It can be used to assure that the application has CORS issues.