2013-04-26 87 views
1

我正在使用此管理員面板模板確認框。Jquery確認和CodeIgniter刪除

http://themepixels.com/main/themes/demo/webpage/shamcey/elements.html

當我點擊確認對話框的確定​​按鈕,ajax的部分不會工作。

我不明白爲什麼它不工作?

這裏我的代碼:

// jQuery的部分

<script> 
jQuery(document).ready(function(){ 
if(jQuery('.confirmbutton').length > 0) { 
    jQuery('.confirmbutton').click(function(){ 
     jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) { 
      if(r==true){ 
       var article_id=$(this).attr("id"); 
       $.ajax({ 
        type:"POST", 
        url: "<?php echo site_url()?>admin/delete",data: "id="+article_id+"&categ=article",asynchronous: true,cashe: false,beforeSend: function(){}, 
        success: function(){ 
        $('#delete_link_'+article_id).hide(); 
        } 
        }); 
      } 
     }); 
    }); 
} 
}); 
</script> 

// HTML

<tr id="delete_link_15"> 
<td>15</td> 
<td>1</td> 
<td>asg</td> 
<td>etc</td> 
<td>etc</td> 
<td> 
<span class="btn-group"> 
<a class="btn btn-small confirmbutton"><i class="icon-trash"></i></a> 
</span> 
</td> 
</tr>   
+0

你可以在'if(r == true)'condition和'console.log('Inside If')之前放置'console.log('If If')'if' r == true){' – 2013-04-26 15:54:24

+0

var parca = jQuery(this).parent('span')。parent('td')。parent('tr')。attr(「id」); 這部分沒有工作。 – TahsinGokalp 2013-04-26 16:41:11

+0

ID'。 」>​​<跨度類=「 BTN-基」> TahsinGokalp 2013-04-26 16:42:41

回答

0

HTML代碼

<tr id="delete_link_15"> 
<td>15</td> 
<td>1</td> 
<td>asg</td> 
<td>etc</td> 
<td>etc</td> 
<td> 
<span class="btn-group"> 
<a class="btn btn-small confirmbutton" onclick="deleteArticle('15')"><i class="icon-trash"></i></a> 
</span> 
</td> 
</tr> 

jQuery代碼

<script> 
jQuery(document).ready(function(){ 
function deleteArticle(article_id) 
{ 
      var r=confirm("Can you confirm this?") 
      if(r==true){ 

       $.ajax({ 
        type:"POST", 
        url: "<?php echo site_url()?>admin/delete",data: "id="+article_id+"&categ=article",asynchronous: true,cashe: false,beforeSend: function(){}, 
        success: function(){ 
        $('#delete_link_'+article_id).hide(); 
        } 
        }); 
      } 

} 
</script>