2013-02-21 4 views
2

에서 웹 서비스를 호출 할 때 다음과 같은 타이프 라이터 구현이 있습니다오류 타이프 라이터

은 그것이 실패 방법 및 반환에 점점 유지
var GRCcontrol; 
(function (GRCcontrol) { 
    (function (Messaging) { 
     var Notifier = (function() { 
      function Notifier(serviceUrl) { 
       this.serviceUrl = serviceUrl; 
       jQuery.support.cors = true; 
      } 
      Notifier.prototype.getNotifications = function (onNotificationReceived) { 
       var that = this; 
       $.getJSON(that.serviceUrl, { 
       }, function (response) { 
        alert(response); 
       }).fail(function (err) { 
        alert(err.statusText); 
       }); 
      }; 
      return Notifier; 
     })(); 
     Messaging.Notifier = Notifier;   
    })(GRCcontrol.Messaging || (GRCcontrol.Messaging = {})); 
    var Messaging = GRCcontrol.Messaging; 
})(GRCcontrol || (GRCcontrol = {})); 
$(document).ready(function() { 
    var notifier = new GRCcontrol.Messaging.Notifier("http://clwebsvr01/wp7test/api/user/getemail/P6dNT1EFOKYPtHxdPWgng2lKyMg="); 
    notifier.getNotifications(function (notifications) { 
     alert(notifications); 
    }); 
}); 

문제가되는 :

/// <reference path="jquery.d.ts" /> 
interface INotificationService { 
    serviceUrl: string; 
    getNotifications(onNotificationReceived: (notifications: string) => any): void; 
} 
module GRCcontrol.Messaging { 
    export class Notifier implements INotificationService { 
     private serviceUrl: string; 
     constructor(serviceUrl: string) { 
      this.serviceUrl = serviceUrl; 
      jQuery.support.cors = true; 
     } 
     getNotifications(onNotificationReceived: (notifications: string) => any) { 
      var that = this; 
      $.getJSON(that.serviceUrl, {}, function (response) { 
       alert(response); 
      }).fail(function (err) { 
       alert(err.statusText); 
      }); 
     } 
    } 
} 
$(document).ready(function() { 
    var notifier = new GRCcontrol.Messaging.Notifier("http://clwebsvr01/wp7test/api/user/getemail/P6dNT1EFOKYPtHxdPWgng2lKyMg="); 
    notifier.getNotifications(function (notifications) { 
     alert(notifications); 
    }); 
}); 

자바 스크립트의 출력이입니다 status = 0 및 statusText = error. 나는 피들러를 사용하여 통화가 완료되었는지보고 피들러가 문제없이 응답을받습니다.

어떻게하면 제대로 작동합니까?

+1

이것은 TypeScript 문제 일 가능성이 낮습니다. JavaScript 태그를 추가하고 TS 컴파일러에서 JS 출력을 게시하면 문제를 진단하는 데 도움이 될 수 있습니다. – JcFx

+0

@JcFx 추가 정보로 내 질문을 업데이트했습니다. –

+0

그게 더 쉽다고 생각합니다. JS 자신이 잘못한 것을 볼 수는 없지만 JQuery에 대한 더 많은 지식이있는 사람들이 여기 있습니다. 내가 할 수있는 유일한 방법은'console.log''that.serviceUrl'을'getNotifications'에 넣어 올바른지 확인하고 전체 서버 응답을 기록하거나 문제가 무엇인지 알기 위해 디버거를 멈추게하는 것입니다 -하지만 이전에이 모든 일을 잘 해왔을 수도 있습니다. – JcFx

답변

2

이것은 TypeScript 문제가 아니지만 cors ajax 호출을 사용하도록 설정하려는 JavaScript/JQuery의 문제가있는 것 같습니다.

cors은 모든 도메인 간 리소스에 대한 포괄적 인 액세스를 허용하지 않습니다. 이 질문에 대한 자세한 내용은 다음을 참조하십시오. Is it safe to use $.support.cors = true; in jQuery?