2016-05-13 13 views
0

I WCF-Dienste unter Verwendung von AJAX, unten zu nennen versuchen mein Code:Wie kann ich diesen Fehler beheben

$.ajax({ 
    url: "http://localhost/TestingServices/Service1.svc/GetData" 
    data: "{'value:1}", 
    type: "POST", 
    dataType: "json", 
    contentType: "application/json; charset=utf-8", 
    success: function(data) { 
     alert(data); 
    }, 
    error: function(XMLHttpRequest, textStatus, errorThrown) { 
     alert(textStatus); 
    } 
}); 

Aber nach Ausführung gibt es mir folgende Fehlermeldung:

XMLHttpRequest cannot load 
    http://localhost/TestingServices/Service1.svc/GetData.Response to 
    preflight request doesn't pass access control check: 
    No 'Access-Control-Allow-Origin' header is present on 
    the requested resource. Origin 'null' is therefore not 
    allowed access. The response had HTTP status code 404. 

Can jemand mir helfen, wie das zu lösen?

+0

entfernen content: „application/json; charset = utf-8 "und dann versuchen ,,, –

+0

bitte http://stackoverflow.com/questions/33820142/getting-request-doesnt-pass-access-control-check-no-access-control-allow-orig – RRR

+0

Nun, ich bekomme dis-Fehler: POST http: //localhost/Wcf/service1.svc/GetData 415 (Die Nachricht kann nicht verarbeitet werden, da conten t type 'application/x-www-form-urlencoded; charset = UTF-8 'war nicht der erwartete Typ' text/xml; charset = utf-8 '.) – tiya

Antwort

0

Versuchen 2 HttpProtocols in web.config Ihres Service-Projekt hinzufügen

<system.webServer> 
    <httpProtocol> 
     <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
     <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> 
     </customHeaders> 
    </httpProtocol> 
</system.webServer> 
0

versuchen Sie bitte diese ein ....

$.ajax({ 
type: "GET", 
url: "http://localhost/TestingServices/Service1.svc/GetData", 
dataType: "jsonp", 
success: readData(data), 
error: function (xhr, ajaxOptions, thrownError) { 
    alert(xhr.status); 
    alert(thrownError); 
} 
}) 
Verwandte Themen