Reputation: 129
I have request json data from other website, but it meets the problem of access control allow origin in header, I have no idea how to set the access control allow origin in header, I'm put my source code in the iis8 to access the json data from another iis8 api source.
$.ajax({
type: "GET",
url:rootURL,
xhrFields: {
withCredentials: false
},
headers: {
"Access-Control-Allow-Origin: ": "*",
"Access-Control-Allow-Methods: ": "GET",
"Access-Control-Allow-Headers: ": "Authorization",
},
dataType: "json",
success: function(data) {
},
error: function() {
alert("An error occurred while processing JSON file.");
}
});
Upvotes: 2
Views: 11407
Reputation: 167162
These should be in the server, not the client:
"Access-Control-Allow-Origin: ": "*",
To implement that in server, for PHP:
<?php
header("Access-Control-Allow-Origin: *");
For ASP.NET:
Response.AppendHeader("Access-Control-Allow-Origin", "*");
For others, check I want to add CORS support to my server for more information.
Upvotes: 5