1

WCF Web サービスへのクロス ドメイン jQuery ajax 呼び出しを使用しています。CORS アプローチを使用していましたが、エラー ブロックが起動しません。jsonp アプローチを試してみると、起動しています。コードをよく見てください。

CORS:

 function faultCLick() {
       $.support.cors = true;
         $.ajax({
            url: "http://mydomain:84/AuthService.svc/ErrorHandling",
            type: "POST",
           contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function res(msg) {
                jsonpTest = msg;
                alert("inside success ");
            },
              error: function (message) { // not firing
                            debugger;
                            var jsonFault = JSON.parse(message.responseText);
                            alert(jsonFault.Message);
                       }
         });
    }

サービス:-

[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "ErrorHandling")]
string ErrorHandling();

ありがとう。

4

1 に答える 1

0

なぜ以前に発砲しなかったのかはわかりません。現在、正常に動作しています。これが私のコードです。

    $.support.cors = true;
    $.ajax({
        type: "GET",
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        url: "http://mydomain:89/MyAppAppService.svc/GetFolders",
        success: function (msg) {
            alert("Success");
        },
        error: function (jqXHR, status, message) {
          alert(jqXHR.responseText);
          alert(status + " " + message);
        }
    });

ありがとう。

于 2013-08-28T08:25:03.277 に答える