• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need help in ajax with codeigniter

#1
[eluser]mohamed eid[/eluser]
hello all
i have controler
Code:
class Test extends CI_Controller
{
   function __construct()
   {
      parent::__construct();
      $this->load->model('product_pics_model');
      $q=$this->input->is_ajax_request('q');
   }


   function index()
   {
     $data['pics']=$this->product_pics_model->getall();
     $this->load->view('test',$data);
   }


function getpic($q)
{
    $q=$this->input->is_ajax_request('q');
    $query=$this->product_pics_model->get_images_byid($q);
    $data['row']=$query->row();
    $this->load->view('test2',$data);
}    
}
and view code
Code:
[removed]
function showUser(str){
   if(str==""){
      document.getElementById("txtHint")[removed]="";
      return;
   }

   if(window.XMLHttpRequest){// for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
   else{// for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }

   xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 && xmlhttp.status==200){
         document.getElementById("ajax_data")[removed]=xmlhttp.responseText;
      }
      else{
         document.getElementById("ajax_data")[removed]="Loading...";
      }
     }
   //xmlhttp.open("GET","/test/getpic/q="+str,true);
   xmlhttp.open("GET","<?php echo base_url(); ?>test/getpic/q="+str,true);
   xmlhttp.send();
}
</script>
<ul>
<?php foreach($pics as $pic):?>
&lt;li&gt;&lt;a href="#" onclick="showUser(this.value)" value="&lt;?php echo $pic-&gt;id; ?&gt;">&lt;?php echo $pic->image1; ?&gt;:&lt;?php echo $pic->id; ?&gt;</a></li>
&lt;?php endforeach;?&gt;
</ul>

<div id="ajax_data">
show data here
</div>

i want when i press on the pic the data of this pic show in the div ajax_data
but i cant do it by codeigniter
can any one help me and do this code


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.