我有三个div,如何只在一个特定的div加载数据而不重新加载php-codeigniter中的完整页面?

时间:2014-11-28 04:17:08

标签: php jquery css ajax codeigniter

我有三个div标签,点击链接我只想在第二个div中加载数据而不加载完整的页面,我想保持第一个和第三个div为静态,第二个div应该是动态的?

   <div class="first">

   <a href="patientLogin/patientVisit_details/<?php echo $data->patient_visit_id;?>"><?php echo $data->hospital_name;?></a>

   </div>


   <div class ="second">
   //content//
   <div>


   <div class ="third">
   //content//
   <div>

2 个答案:

答案 0 :(得分:1)

只是尝试从ajax函数返回所需的值。这样的事情可能会这样做。如果你有一个insert.php文件,你可以echo or return data } {需要填充到页面中的function的末尾

$('.first a').click(function(){
    $.ajax({
        type: "POST",
        url: "insert.php",
        cache: false,
        success: function(data){
                 //Now you have obtained the data that was was returned from the function
                 //if u wish to insert the value into an input field try
               $('.second').html(data); //now the data is populated in the input field 

         }
        });
})

有关详细信息,请查看此link

答案 1 :(得分:1)

你可以通过ajax实现这些。

1) As you want to apply dynamic data loading on some click event of some anchor link then please don't apply anchor link as:
"<a href="patientLogin/patientVisit_details/<?php echo $data->patient_visit_id;?>"><?php echo $data->hospital_name;?></a>" the anchor leads you to the href value link. alternatively you can do like (<a href="javascript:void(0);">);

现在你的CI案件; 在视图中:

<a href="javascript:void(0);"onclick="javascript:changeData('<?php echo $data->patient_visit_id;?>')"><?php echo $data->hospital_name;?></a>

在Js文件中

function changeData(parentVisitId){

 var urlCI = 'patientLogin/patientVisit_details/'+parentVisitId;

 $.ajax({
        type: "GET",
        url: urlCI,
        data:{
            'parenIdIfReq':parentVisitId,
        },
        success: function(response) {
            if(response!=''){
                $('.second').html(response);
            }
            else{
                return false;
            }
        }
    });

}
In controller/action i.e patientLogin/patientVisit_details/parentVisitedId
 function patientVisit_details($parentVisiteId){
    echo "whatever data you want to return as response";
 }