Hi da bin ich fest und finde irgendwie die Lösung nicht. Es scheint einfach, aber gut, ok. Hier kommt's. Ich habe einen mobilen Dienst in Azure und möchte diesen mit Javascript erreichen. Wie komme ich um die 401 Unauthorized? Ich habe es mit der Dokumentation von MS versucht, aber kein Glück. Das ist, was ich bis jetzt bekommen habe (das Hinzufügen des Schlüssels zur URL funktioniert natürlich nicht) Was kann ich hinzufügen, um es zum Laufen zu bringen?Azure Mobile Service und Javascript
var client = new WindowsAzure.MobileServiceClient(
"https://cdshop.azure-mobile.net/",
"vGpqzyApJXXXXXXXXblQCWne73"
);
var getJSON = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
callback(null, xhr.response);
} else {
callback(status);
}
};
xhr.send();
};
$(function() {
$('#clickme').click(function() {
getJSON('http://cdshop.azure-mobile.net/api/cds/total?key=vGpqzyApJXXXXXXXXblQCWne73', function (err, data) {
if (err != null) {
alert('Something went wrong: ' + err);
} else {
alert('Your Json result is: ' + data.result);
result.innerText = data.result;
}
});
});
});
Vielen Dank Eric, es funktionierte wie ein Charme –