Azure移动服务:JavaScript中的基本读取功能 [英] Azure mobile services: basic read function in javascript
问题描述
我正在学习javascript和windowsazure移动服务.在学习课程中,我创建了一个用户"表并插入了一个测试用户.我实际上是使用icenium为ipad和Andoid平板电脑编写一个演示应用程序,但即使是最基本的请求,我似乎也无法弄清楚.因此,我在这里设置了jsfiddle: http://jsfiddle.net/MNubd/5/.
I'm learning javascript and windowsazure mobile services. As a learning lesson I created a "users" table and inserted a test user. I'm actually using icenium to write a demo app for the ipad and andoid tablets, but I can't seem to figure out even the most basic request. So I've setup a jsfiddle here: http://jsfiddle.net/MNubd/5/.
这是一个简单的输入框:
It is a simple input box:
<input id="uFullName" type="text" />
和一些javascript代码.我正在尝试从用户"表中检索名称"列,并将其显示在输入框中:
and some javascript code. I'm trying to retrieve the "name" column from the table "users" and display it in the input box:
alert('running');
var client = new WindowsAzure.MobileServiceClient('https://mtdemo.azure-mobile.net/', 'MtxOqGpaBzuPRtnkIifqCKjVDocRPY47');
usersTable = client.getTable('users');
usersTable.where({ userID: 'impretty@blockedheaded.com' }).read({
success: function (results) {
$('#uFullName').val(results);
},
error: function (err) {
$('#uFullName').val('there was and err');
}
});
感谢您的帮助!
我不知道成功功能只能在服务器脚本上使用.谢谢.这是最终对我有用的代码:
I had no idea the success function could only be used on server scripts. Thanks. Here is the code that ended up working for me:
function signInButton(e) {
var un = $('#username');
uName = un.val();
var client = new WindowsAzure.MobileServiceClient('https://mtdemo.azure-mobile.net/', 'MtxOqGpaBzuPRtnkIifqCKjVDocRPY47');
//alert('lookup: ' + uName);
usersTable = client.getTable('users');
usersTable.where({ userID: uName })
.read()
.done(
function (results) {
try {
xUserName = results[0].name; //using this to trigger an exception if the login credentials don't match.
xUserID = results[0].id; // save this for querying and adding records for this user only.
//alert('found');
app.application.navigate('#view-menu');
}
catch(err) {
//alert('not found');
document.getElementById('errorText').textContent = "Check Email and Password!";
}
}
);//end of the done
推荐答案
带有成功
和 error
回调对象的options对象仅在服务器端脚本中使用.对于客户端,编程模型是基于Promise的,您应该使用 done()
(或 then()
)延续来获得结果:
The options object with the success
and error
callback objects is only used in server-side scripts. For the client side, the programming model is based on promises, and you should use the done()
(or then()
) continuation to get the results:
var client = new WindowsAzure.MobileServiceClient('https://mtdemo.azure-mobile.net/', 'YOUR-KEY');
var usersTable = client.getTable('users');
usersTable.where({ userID: 'impretty@blockheaded.com' }).read().done(function (result) {
$("#uFullName").val(result.name);
}, function (err) {
$("#uFullName").val('There was an error: ' + JSON.stringify(err));
});
这篇关于Azure移动服务:JavaScript中的基本读取功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!