2014-09-06 36 views
0

我有问题ajax。当我不能在AJAX使用的href属性POST方法.. 发送值这个阿贾克斯我的源代码...在CI上使用Post方法在ajax上发送href值hp

function show_TIM(){ 
    var img = "<img src='"+site_url+"public/images/load.gif' align='center'>"; 
    $("#TIM").html(img); 
    event.preventDefault(); 
    $.ajax({ 
     type:"post", 
     url: site_url+'index.php/controller/function/#needvaluerighthere', 
     data: { 
       link : $(this).attr('href'), 
      }, 

     success:function(msg){ 
      $('#TIM').html(msg); 
      oTable = $('#example').dataTable({ 
        "bJQueryUI": true, 
        "sPaginationType": "full_numbers", 
        'iDisplayLength': 100 
      }); 
     } 
    }); 
} 

和HMTL代码

<a href="'.$row['TIM_KE'].'" class="link" style="text-decoration: none;" data-toggle="modal" data-target=".TIM" data-artid="'.$row['TIM_KE'].'" onclick="show_TIM();"> 

我试图抓住$行[ “TIM_KE”]用Ajax和值发送到控制器... 总之,我使用CodiIgniter ... 请帮助我..

回答

0

您将有一个增加一个click事件侦听器,不具备的功能

事件调用

$(document).on('click', 'a', function() { 
    show_TIM($(this).attr('href')); 
}); 

AJAX调用

function show_TIM(value){ 
    var img = "<img src='"+site_url+"public/images/load.gif' align='center'>"; 
    $("#TIM").html(img); 
    event.preventDefault(); 
    $.ajax({ 
     type:"post", 
     url: site_url+'index.php/controller/function/#needvaluerighthere', 
     data: { 
       link : value, 
      }, 

     success:function(msg){ 
      $('#TIM').html(msg); 
      oTable = $('#example').dataTable({ 
        "bJQueryUI": true, 
        "sPaginationType": "full_numbers", 
        'iDisplayLength': 100 
      }); 
     } 
    }); 
} 
+0

千恩万谢的参考,你是对的... – sidzaky 2014-09-06 11:24:01