I've implemented the following TypeScript code:
/// <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);
});
});
This is how the JavaScript output looks like:
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);
});
});
The issue here is that it keeps failing and returning status = 0 and statusText = error. I checked with Fiddler to confirm if the call was made successfully, and indeed Fiddler receives the response without issues.
How can I resolve this problem and make everything work smoothly?