2013-01-25 93 views
-2

Uncaught TypeError: Object has no method 'stopImmediatePropagation'遗漏的类型错误:对象没有方法“stopImmediatePropagation”

jquery error

下面是完整的代码,我从9lessons网站获得。

$(document).ready(function() 
{ 
    $(".delete").live('click',function() 
    { 
     var id = $(this).attr('id'); 
     var b=$(this).parent().parent(); 
     var dataString = 'id='+ id; 
     if(confirm("Sure you want to delete this update? There is NO undo!")) 
     { 
      $.ajax({ 
       type: "POST", 
       url: "delete_ajax.php", 
       data: dataString, 
       cache: false, 
       success: function(e) 
       { 
        b.hide(); 
        e.stopImmediatePropagation(); 
       } 
      }); 
     return false; 
     } 
    }); 
} 

错误指向e.stopImmediatePropagation();

我怎样才能解决这个问题?谢谢!

+4

您的代码中的'e'是Ajax响应,而不是事件对象。 – undefined

+0

你想要做什么? Ajax请求没有您希望停止传播的事件 –

+1

总是第一步是检查jQuery文档。查看'$ .ajax'的'success'来了解它接受的参数。 http://api.jquery.com/jQuery.ajax/ – elclanrs

回答

2

你需要在你的函数clickhandler事件对象:

$(".delete").live('click',function(e) 
+2

该行位于'success'回调函数中 –

3

传递给成功的功能应该是一个数据对象,而不是一个事件的第一个变量。好像你想抓取点击事件并取消它,因为你正在处理它。所以在顶部,使用这个:

$(".delete").live('click',function(event) 
{ 
    event.stopImmediatePropagation(); 
    ...everything else... 
}); 

并删除原来的e.stopImmediatePropagation();

-1

这应该这样做...

$(document).ready(function() 
{ 
$(".delete").live('click',function(evt) 
{ 
var id = $(this).attr('id'); 
var b=$(this).parent().parent(); 
var dataString = 'id='+ id; 
if(confirm("Sure you want to delete this update? There is NO undo!")) 
{ 
    $.ajax({ 
type: "POST", 
url: "delete_ajax.php", 
data: dataString, 
cache: false, 
async: false, 
success: function(e) 
{ 
b.hide(); 
evt.stopImmediatePropagation(); 
} 
      }); 
    return false; 
} 
}); 

注意async: false;,这会让你的代码执行等待阿贾克斯完成,将停止click事件。您无法从异步成功处理程序停止事件。

相关问题