【发布时间】:2016-07-14 20:21:44
【问题描述】:
您好,我被卡住了,不知何故找不到解决方案。看起来很简单,但是,好吧。就这样吧。我在 Azure 中有一项移动服务,我想使用 javascript 访问该服务。我如何绕过 401 Unauthorized?我尝试使用 MS 提供的文档,但没有运气。这是我到目前为止所得到的(当然,将密钥添加到 url 是行不通的)我可以添加什么来让它工作?
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;
}
});
});
});
【问题讨论】:
标签: javascript authentication azure-mobile-services