0
Refer & try below
1) https://www.html5rocks.com/en/tutorials/cors/#toc-types-of-cors-requests
2) Do you try to modified the web.config for the webservice to add the following line yet ?
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol>
3) I found the solution to my problem. Seems like I haven't been paying full attention of the error message properly :)
After I added the Access-Control-Allow-Origin header into my web.config file, it turns out I started getting some other error, which was content-type custom header was missing and I thought I was still getting the CORS error.
So, adding the <add name="Access-Control-Allow-Origin" value="*" /> definition into my web.config actually solved my cross-origin problem in the first place! And I also have tested to allow specific domains or requests from ports with the following web.config header entry and it also worked like charm - since I think it is the best option to use since I will not be publishing my services publicly.
<add name="Access-Control-Allow-Origin" value="http://localhost:17256" />
4) https://stackoverflow.com/questions/12296910/so-jsonp-or-cors
5) Or just add the proper header in your web.config from your web api site:
- <?xml version="1.0" encoding="utf-8"?>
- <configuration>
- <system.webServer>
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="*" />
- <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
- </customHeaders>
- </httpProtocol>
- </system.webServer>
- </configuration>
6) Try
- $.ajax({
- crossDomain: true,
- contentType: "application/json; charset=utf-8",
- type: "GET",
- url: "https://mail.google.com/mail/feed/atom/",
- dataType: "xml",
- cache: false,
- headers: {
- "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
- },
- success: function (result) {
- alert("XML File is loaded!");
- alert(result);
- }
- });
-
All the best
