2013-01-25 96 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事件。您無法從異步成功處理程序停止事件。

相關問題