2016-05-13 9 views
0

このエラーを解決するにはどうすればよい、以下の私のコードです:は私がAJAX</em>を使用して<em>WCFサービスを呼び出すためにしようとしています

$.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); 
    } 
}); 

しかし、実行後、それは私に次のエラー与える:

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. 

できます誰も私にこれを解決する方法を助ける?

+0

削除のcontentType:「アプリケーション/ jsonの;のcharset = UTF-8 "そして、試して,,, –

+0

親切に参照してくださいhttp://stackoverflow.com/questions/33820142/getting-request-doesnt-pass-access-control-check-no-access-control-allow-orig – RRR

+0

今、私は得るdisエラー:POST http://localhost/Wcf/service1.svc/GetData 415(メッセージを処理できませんtタイプ 'application/x-www-form-urlencoded; charset = UTF-8 'は予想されるタイプ' text/xmlではありませんでした。 charset = utf-8 ')。 – tiya

答えて

0

.... 2は、あなたのサービスプロジェクトのweb.configファイルにHttpProtocolsを追加

<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

、このいずれかを試してみてくださいしてみ

$.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); 
} 
}) 
関連する問題