2013-10-30 24 views
0

我想将工具提示的数据传递给div。 看到这个图像enter image description here从工具提示发送数据到div不工作

我想通过ID当我们点击广告的接触(见图片)

我尝试了许多代码,但没有成功呢。

尝试这个javascript代码,但是这是工作在页面的其他部分,但是当我试图在此提示其没有工作.. 怎么办????

<script type="text/javascript"> 

//send clicker data to div 
    $(function() { 
     $(".clicker").click(function(){ 
      var data = $(this).attr('id'); 
      $.ajax({ 
       type: "POST", 
       data: "db_data=" + data, 
       success: function(){ 
        //alert(data); 
        $('.div-5-owner').text(data); 
       } 
      }); 
     }); 
    }); 
</script> 
+0

您已将变量命名为data,它也是ajax调用中的属性名称。尝试更改'数据'以外的其他变量的名称 – Mozak

回答

0

通行证datasuccesscallback

success:function(data){ // <-- you missed data here which is your server response 
      //alert(data); 
      $('.div-5-owner').html(data); 
} 
+0

请详细说明我是新的jquery – dvirus

+0

rohan请给我完整的代码。我是新的阿贾克斯和jquery – dvirus

+0

rohan我试过你的代码,它发送所有的html代码到div – dvirus

0

尝试改变该部分

success: function(my_text){ 
        //alert(my_text); 
        $('.div-5-owner').text(my_text); 
       } 

数据被保留可变

0

您正在使用的数据变量用于分配ID而这是一个保留字$阿贾克斯()。
更改变量的名称和尝试:

$(".clicker").click(function(){ 
      var id1 = $(this).attr('id'); 
      console.log(id1); 
      console.log("db_data=" + id1); 
      $.ajax({ 
       type: "POST", 
       data: "db_data=" + id1, 
       success: function(response){ // Here pass the server response as any variable like I used response 
        //alert(response); 
        $('.div-5-owner').text(response); 
       } 
      }); 

     }); 
}); 

它应该工作,只要你想。