Ich benutze jquery, um eine externe API mit Ajax zu treffen.Chrome jquery ajax zu externen api Fehler
$.ajax({
url: https://blahblah,
method: "GET",
contentType: "text/plain",
dataType: "json",
crossDomain: true,
accept: "application/json",
async: true,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Origin, Content-Type, Accept",
success: function (data) { //more code}
Alles funktioniert gut in IE aber wegen der gleichen Ursprungsrichtlinie von Chrome funktioniert es nicht. Dies ist der Fehler, den ich immer bin in der Konsole
XMLHttpRequest cannot load https://blahblah.
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8889' is therefore not allowed access.
localhost/ Failed to load resource: the server responded with a status of 403 (Forbidden)
Dies ist, was die Header aussehen
Response Headers
HTTP/1.1 200 OK
Date: Fri, 23 Jun 2017 15:05:44 GMT
Server: xxxxx
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Connection: close
Transfer-Encoding: chunked
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:access-control-allow-headers,access-control-allow-methods,access-control-allow-origin,x-frame-options
Access-Control-Request-Method:GET
Connection:keep-alive
Host:blahblah
Origin:http://localhost:8889
Referer: http://localhost:8889/
Da dies ein .net MVC4 ist IIS 7.5 app Ich habe versucht, die benutzerdefinierten Header in der WEB.CONFIG-Datei zu setzen, aber es hat auch nicht funktioniert
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Methods" value="GET"/>
<add name="Access-Control-Allow-Headers" value="*"/>
</customHeaders>
</httpProtocol>
Bitte se helfen
Das ist lächerlich . Es muss einen Workaround geben. Sie können nicht allen Benutzern mitteilen, ein Chrome-Plug-in zur Verwendung Ihrer App zu installieren – Wil