我正在使用NET MVC处理这个小项目,我能够将新用户添加到我的数据库中,它很好地显示在我的UI中,不知何故我不能从UI中删除。我没有得到任何错误所以请帮助。预先感谢。
public JsonResult DeleteUser(string username)
{
try
{
MyData.DB.Base.User.Delete(username);
return new JsonResult() { Data = new { completed = true, username } };
}
catch
{
return new JsonResult() { Data = new { completed = false, username } };
}
}
这是我的javascipt代码:
User.UserRemoveFromUsers = function (username) {
$.ajax({
url: '/User/DeleteUser',
type: "POST",
data: "username=" + username,
success: function (data) {
if (data.completed == true) {
$('div.user[data=' + data.username + ']').remove();
}
}
});
};
答案 0 :(得分:1)
替换data: "username=" + username,
收件人:data: { username : username },
User.UserRemoveFromUsers = function (username) {
$.ajax({
url: '/User/DeleteUser',
type: "POST",
data: { username : username },
success: function (data) {
if (data.completed == true) {
$('div.user[data=' + data.username + ']').remove();
}
}
});
};