首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

ajax删除 看下有关问题在哪

2014-01-19 
ajax删除大虾看下问题在哪本帖最后由 u013177533 于 2014-01-14 17:34:30 编辑函数不执行 大虾看看那错了

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>


handler类
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用json吧,再把error加上,看是不是进error了,再看error里面具体的消息

$.ajax({
data:{id:id},
error:function(data){
alert(data.responseText);
}
});

热点排行