cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted

CORS 500 error while accessing subdomain REST API

I have a domain lets say www.cv5.com.

I created a subdomain aspapi.cv5.com

I published a REST Service on to this subdomain and when Im using Postman, It works perfectly with a response.

Now, I have a page load.html in www.cv5.com which tries to get the REST JSON from aspapi.cv5.com, Im getting CORS error : 

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://aspapi.cv5.com/apiv2/api/FService/GetCurrentLocation. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

 
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://aspapi.cv5.com/apiv2/api/FService/GetCurrentLocation. (Reason: CORS request did not succeed).
Here is what I have done so far. 
1. Added the below to the JSON call.
$.ajax({
type:"GET",
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
'Content-Type':'application/json'
},
url: "http://aspapi.cv5.com/apiv2/api/FService/GetCurrentLocation"
}).done(function(response){
curLocn = response;
updateMap();
});
 
2. Added .htaccess file to both domain and subdomain
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header merge Vary Origin
 
What am I missing here...
1 REPLY 1

Re: CORS 500 error while accessing subdomain REST API

@CV67 

 

Try using the following in your rest API 

Header set Access-Control-Allow-Origin *

 

Then remove the headers from your AJAX request.... Like all of it.

 

~Jan Mykhail Hasselbring Web Administrator @ fullstackwebsolution.com