douhuan1905 2015-03-04 12:31
浏览 23
已采纳

点击事件解雇但ajax没有发生

I am loading data rows using ajax, now i am trying to delete row by clicking delete image icon in that row( delete image is <input type='image' loading with row data).

now by clicking on delete row icon it is firing but ajax not running to delete data in MySql Db.

$(document).ready(function(){
   $(document.body).on('click', '.deleterow', function(){
   var userid = $(this).val();    
   var examid = $("#examid").val();    
   //alert(userid);
        $.ajax({
        type:"POST",
        url:"deletecandidateexam.php",
        data:"candid="+userid+"examid="+examid,
        dataType:"json",
        success: function(data){
            if(data = "norecord"){
                alert("No Recodrs Found to Delete Selected Candisate..");
            }if(data = "success"){
                $(this).parent().parent().remove();                    
            }if(data = "failure"){
                alert("Failed to Delete Selected Candisate, Please Try Later..");                   
            }       
        }
    });    
 });      
});
  • 写回答

1条回答 默认 最新

  • dsoihsnz85757 2015-03-04 12:36
    关注

    you need to prevent the default action of the button otherwise your form will get submitted:

    $(document.body).on('click', '.deleterow', function(e){
        e.preventDefault();
        .... rest of code
    });
    

    And fix the data error:

    data: 'candid=' + userid + '&examid=' + examid
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀