0

我有以下代码。

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();
        }
    }
    }

我正在使用这个脚本来验证用户是否被允许删除他请求的内容,即用户删除的用户ID 与表中的用户ID 匹配。

一切正常,我到达

    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);
    }
  });
}
4

2 回答 2

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);
    }
    });
}
于 2013-09-24T19:00:23.510 回答
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);
    }
});
于 2013-09-25T02:38:44.077 回答