私は次のtypescript実装を持っています:
/// <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);
});
});
Javascriptの出力は次のとおりです。
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);
});
});
問題は、failメソッドに入り続け、status=0およびstatusText=errorを返すことです。Fiddlerを使用して呼び出しが行われたかどうかを確認したところ、fiddlerは問題なく応答を受信しました。
どうすればこれを正しく機能させることができますか?