我有以下代码。
C#代码在设备上,Windows Phone 8:
IMobileServiceTable<Subscription> SubsciptionsTable = App.MobileService.GetTable<Subscription>();
SubscriptionItemServerItem = await SubsciptionsTable.Where(subs => subs.userId == App.UserInfromationID && subs.ContentID == holdElement.NewMessages).ToListAsync();//only want items that are something
await SubsciptionsTable.DeleteAsync(SubscriptionItemServerItem[0]);
我将删除请求发送到Azure MobileService的位置。 我在这里有以下脚本:
function del(id, user, request) {
var TableA_Table = tables.getTable('subscription');
//console.log("About to Delete Subscription:", id);
TableA_Table.where({ userId: user.userId, id: id})
.read ({ success: DeleteItem });
function DeleteItem(results)
{
if(results > 0){
console.log("Reached HERE", id);
request.execute();
}
}
}
我正在使用此脚本来验证用户是否可以删除他请求的内容,即userdleting的userId与表中的userId匹配。
一切正常,我到达了
request.execute();
然后它挂了,我在等待电话,超时。 并且该项目也不会在服务器上删除。
我该怎么办?什么可能导致错误?
解决方案
我仍然没有在我的脚本中找到错误。但通过调整我得到的响应,我标记为已回答我找到了解决方案:
function del(id, user, request)
{
var table = tables.getTable('subscription');
table.where({ id: id }).read({
success: function (results)
{
if (results.length > 0)
{
//console.log("log existingItem",results[0].userId);
//console.log("log user",user.userId);
if (results[0].userId == user.userId)
{
request.execute();
}
else
{
// console.log("Invalid user");
request.respond(statusCodes.BAD_REQUEST, "Invalid user");
}
}
else
{
// console.log("NOT_FOUND");
request.respond(statusCodes.NOT_FOUND);
}
}, error: function () {
//console.log("NOT_FOUND_error");
request.respond(statusCodes.NOT_FOUND);
}
});
}
答案 0 :(得分:2)
尝试将“删除”功能更新为:
function delete(item, user, request)
{
var table = tables.getTable('subscription');
table.where({ id: item.id }).read({
success: function (results)
{
if (results.length)
{
var existingItem = results[0];
if (existingItem.UserId === user.userId)
{
request.execute();
}
else
{
request.respond(statusCodes.BAD_REQUEST, "Invalid user");
}
}
else
{
request.respond(statusCodes.NOT_FOUND);
}
}, error: function () {
request.respond(statusCodes.NOT_FOUND);
}
});
}
答案 1 :(得分:1)
在“request.execute();”
行之后调用下面的函数 var sqlSpecs = "DELETE from specifications WHERE subscriptionId = " + id;
mssql.query(sqlSpecs, {
success: function()
{
console.log("ok");
},
error: function(err)
{
console.log("there was a problem deleting specifications with subscriptionId: " + id + ", " + err);
}
});