I have the following typescript implementation:
/// <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);
});
});
The output in Javascript is this:
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 problem is that it keeps getting into the fail method and returns status = 0 and statusText = error. I used Fiddler to see if the call is done, and fiddler receives the response without problems.
How can i get this thing to work properly?
console.logthat.serviceUrlingetNotifications, to make sure it is correct, and also log the entire server response, or put a debugger stop there to see what the issue might be - but you may well have done all this previously.OPTIONScall that CORS uses to check the server is happy to make the actual request?