0

I have three div tags, on click of a link I want to load data in only the second div without loading the complete page, I want to keep the first and third div as static and second div should be dynamic?

   <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>
Madhu
  • 1,925
  • 4
  • 16
  • 33

2 Answers2

1

Just try to return the values that you need from the ajax function.Something like this might do.Soppose you have a insert.php file,you may echo or return the data at the end of the function that needs to be populated into the page

$('.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 

         }
        });
})

For more info check this link

Outlooker
  • 3,866
  • 2
  • 16
  • 36
1

You can achieve these by 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);">);

Now in your case for CI; In view:

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

In Js File

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";
 }
shaishaw
  • 156
  • 3