【发布时间】:2016-07-09 10:33:40
【问题描述】:
我想通过 json 请求删除一行,但不幸的是代码不起作用。
function deleteRecord(id) {
debugger;
// === Show confirmation alert to user before delete a record.
var ans = confirm("Are you sure to delete a record?");
// === If user pressed Ok then delete the record else do nothing.
if (ans == true) {
debugger;
$.ajax({
type: "POST",
url: location.pathname + "WebForm5.aspx/deleteRecord",
data: id,
contentType: "application/json; charset=utf-8",
datatype: "json",
async: "true",
success: function (dt) {
debugger;
//=== rebind data to remove delete record from the table.
$(this).closest('tr').remove();
$(".errMsg ul").remove();
$(".errMsg").append("<ul><li>Record successfully delete.</li></ul>");
$(".errMsg").show("slow");
clear();
},
error: function (dt) {
alert(response.status + ' ' + response.statusText);
}
});
}
}
这是我在 ASP.net 中的 aspx.cs 代码:
public static void deleteRecord(int CategoryID)
{
clsCategoryBL objproject = new clsCategoryBL();
objproject.CategoryDelete(CategoryID);
}
我想解决问题。谁能帮帮我?
【问题讨论】:
-
你需要知道你的代码到底在哪里不工作。它从服务器端得到答案吗?它只是不删除行还是什么?什么不工作?
-
在服务器端它不起作用..你只是在回答中解释我的细节,以便我能理解..
-
我认为问题出在 jquery 代码中。这里的错误数据:id,显示它将直接调用错误:函数(dt){警报(response.status +''+响应.statusText); }
-
所以你没有从服务器端得到答案?服务器端脚本是否与包含 javascript 的文件位于同一目录中?
-
我知道它的库,但语言是 javascript