2010-05-19 51 views
0

我有一個表,當我點擊行時,它會在另一個表中加載一些內容。jQuery,Ajax的問題​​?

問題是,當我第一次點擊一行時,它只加載一次(消息'Some msg'和消息'Some other msg'顯示一次)。當我點擊另一行時,它會加載兩次(消息顯示兩次)。當我點擊連續第三次加載三次,等

這裏是我的代碼:

$("#myTable tr").click(function(e){ 
    $.ajax({ 
     url:'<?php echo $full_path_ajax_php; ?>', 
     data:{'what':'2','mypath':'12345678'}, 
     dataType:'json', 
     type: 'GET', 
     beforeSend:function(){alert('Some msg')}, 
     success: function(){alert('Some other msg')} 
    }); 
    return false; 
}); 

回答

0

您需要使用.live()功能父表,但您要使用的部分不使用此代碼:

$("#myTable tr").live('click', function(e){ 
    $.ajax({ 
     url:'<?php echo $full_path_ajax_php; ?>', 
     data:{'what':'2','mypath':'12345678'}, 
     dataType:'json', 
     type: 'GET', 
     beforeSend:function(){alert('Some msg')}, 
     success: function(){alert('Some other msg')} 
    }); 
    return false; 
}); 

在父頁或表請記住,只有一次。

+0

Tnx男人,那工作正常,我會看現場活動,以更好地理解我的問題.Tnx。 – user147 2010-05-19 05:27:12

+0

來吧,然後至少投我我 – Starx 2010-05-19 05:31:57

+0

我認爲我沒有足夠的聲譽:( – user147 2010-05-19 05:38:57

1

嘗試使用,而不是「TR」的ID,你會得到的ID在功能上的點擊事件。我認爲這可能會奏效,如果我錯了,請糾正我。

+0

我不明白你在說什麼,你能舉個例子嗎? 但仍認爲是不是解決方案.Tnx – user147 2010-05-19 05:16:41

+0

我嘗試使用'id'而不是'tr',仍然不工作,有人可以幫助我,這是討厭的,... – user147 2010-05-19 05:22:38

+0

嘿你有孩子表內# myTable ?? – Chirag 2010-05-19 05:23:43