如何在Azure移动服务api中发出Ajax请求
我想在我的azure移动服务api get方法中发布一篇jquery ajax文章。也就是说,就像我下面所说的。也就是说,我希望GET方法返回从我的ajax文章的结果中返回的数据 不清楚我会怎么做如何在Azure移动服务api中发出Ajax请求,azure,azure-mobile-services,Azure,Azure Mobile Services,我想在我的azure移动服务api get方法中发布一篇jquery ajax文章。也就是说,就像我下面所说的。也就是说,我希望GET方法返回从我的ajax文章的结果中返回的数据 不清楚我会怎么做 exports.get = function(request, response) { $.ajax({ type: "POST", url: url, data: data, success: function(x) { return MYLIST }, dataType:
exports.get = function(request, response) {
$.ajax({
type: "POST",
url: url,
data: data,
success: function(x) { return MYLIST },
dataType: dataType
});
response.send(statusCodes.OK, { message : 'Hello World!' });
};
更新:
Per Carlos Post:我现在知道exports.get代码应该在azure移动服务的API部分。当我将代码放入该部分时,我得到一个内部错误,在jquery调用的失败事件中为500。我的警报显示我已成功登录谷歌
var client = new WindowsAzure.MobileServiceClient('https://svcc.azure-mobile.net/', val);
$(document).ready(function () {
$("#submit1").click(function () {
client.login("google").done(function (results) {
alert("You are now logged in as google: " + results.userId);
$.ajax({
url: "http://xxxxx.azure-mobile.net/api/test1",
success: function (data, textStatus) {
debugger;
//data - response from server
},
error: function (jqXHR, textStatus, errorThrown) {
debugger;
}
});
}, function (err) {
alert("Error: " + err);
});
});
您应该使用一些node.js模块,它允许您发出HTTP请求。最简单的是,您可以在服务器脚本上使用它来发出请求。例如,此代码应该执行您想要的操作:
exports.get = function(request, response) {
var req = require('request');
req({
url: url,
method: 'POST',
body: JSON.stringify({ theBody: [ 'hello', 'world' ]}),
headers: { "Content-Type": "application/json" }
}, function(err, result) {
response.send(statusCodes.OK, result);
}
}
要从谷歌等odata服务获取其他数据,这是一条可行的途径吗?有没有办法访问脚本中azure标识部分的google密钥/机密数据?嗨,卡洛斯,请忽略我的上述评论。现在我更了解你了。我更新了上面的示例,包括从您的示例中调用get方法,现在我得到一个500的内部错误。还有一个提示,Identifications is null是来自test1 api调用的错误。我发现Carlos的另一篇文章说我必须启用它作为预览功能。我这么做了,但我还是没有从GetIdentifications那里得到任何回报。请参见此以了解我是如何启用的。通过启用预览功能用户,更新了上面评论中的图片