ajax删除 大虾看下问题在哪
本帖最后由 u013177533 于 2014-01-14 17:34:30 编辑 函数不执行 大虾看看那错了 调试到不了handler
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="../js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(function () {
$('.delete').click(function () {
var comm = $(this).parent().parent();
var did = comm.attr("id");
$.ajax({
type: "POST",
url: "Salaryajax/Salaryhandler.ashx?action=dl",
data: "&id=" + escape(did),
async: true,
cache: false,
success: function (msg) {
if (msg == "success") {
comm.remove();
}
}
});
});
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<thead>
<tr>
<td>salaryid</td>
<td>name</td>
<td>salary</td>
<td>createtime</td>
<td>action</td>
</tr>
</thead>
<tbody>
<% foreach(var item in list){ %>
<tr class="selftr" id="<%=item.salaryid %>">
<td><%=item.salaryid %></td>
<td><%=item.name %></td>
<td><%=item.salary %></td>
<td><%=item.createtime %></td>
<td>
<a href="update.aspx?id=<%=item.salaryid %>&name=<%=item.name %>&salary=<%=item.salary %>&createtime=<%=item.createtime %>">update</a>
<a href="detail.aspx?id=<%=item.salaryid %>&name=<%=item.name %>&salary=<%=item.salary %>&createtime=<%=item.createtime %>">detail</a>
<a href="#" class="delete">delete</a>
</td>
</tr>
<%} %>
<tr>
<td>
<a href="create.aspx">create</a>
</td>
</tr>
</tbody>
</div>
<div class="create"></div>
</form>
</body>
</html>
public class Salaryhandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
string action = context.Request["action"].ToString();
if (action == "dl")
{
int id = Convert.ToInt32(context.Request["did"]);
T_Salary salary = new T_Salary();
salary.salaryid = id;
new BLL.SalaryBLL().delete(salary);
context.Response.Write("success");
}
}
$.ajax({
data:{id:id},
error:function(data){
alert(data.responseText);
}
});