2014-10-07 119 views
0

我正在試圖在當前div項的子元素中添加ajax加載的內容,但它不起作用,無法找出問題出在哪裏。
如何在當前子元素中加載ajax響應?

這裏是HTML代碼:

<div class="thumb-pitch"> 
<span class="pitch-count" ></span> 
</div> 
<div class="thumb-pitch"> 
<span class="ditch-count"></span> 
</div> 

JS代碼:

$('.thumb-pitch').click(function() { 
var id= $(this).attr('cid'); 
var dataString = 'idea_id='+ id; 
$.ajax({ 
    type: 'POST',  
    url:"<?php echo base_url();?>users/user_votes/user_pitch", 
    data:dataString, 
    success: function(response) { 
    //alert(response);   
    $(this).find('span').html(response); 
    } 
}); 
}); 
+0

阿賈克斯響應是否好? – divakar 2014-10-07 05:33:10

+0

有沒有一個'/'在用戶在URL和$(這個)不會是你認爲 – loveNoHate 2014-10-07 05:33:59

+0

請分享**響應**對象的細節? – Mayank 2014-10-07 05:40:24

回答

1

您需要的$(this)參考存儲在一個變量,然後使用該變量的研製成功回調處理程序。 。

使用

$('.thumb-pitch').click(function() { 
    var id = $(this).attr('cid'); 
    var $this = $(this); //Store this reference in a variable 
    $.ajax({ 
     type: 'POST', 
     url: "<?php echo base_url();?>users/user_votes/user_pitch", 
     data: {"idea_id" : id}, 
     success: function(response) { 
      //alert(response);   
      $this.find('span').html(response); //Use the reference variable here 
     } 
    }); 
}); 
+1

現在它工作正常。 – sangam 2014-10-07 08:44:30

0

可以爲此

$(本)。兒童( '跨度')使用兒童()HTML(響應);

相關問題