title: Codeigniter get ajax response and pass that data from controller to view
body: <p>I have a problem with my Codeigniter app. I want load some data by ajax. In my page I write onclick function to run jQuery function. And in my function I just Post that response to my controller.Here is my jQuery function</p>
  
  <pre><code> function callplayer(filepath,videocode,createdby){
  
          $.ajax({
              type    :   "POST",
              url :       base_url+"home/loadVideo",
              data    :   {id:videocode,video:filepath,user_id:createdby},
              success :   function(html){
                      var container = $('#company'); //jquery selector (get element by id)
                         if(html){
                            container.html(html);
                         }
  
              }
          });
  
       } 
  </code></pre>
  
  <p>And here is my loadVideo function ( My controller )</p>
  
  <pre><code>function loadVideo(){
          $user_id = $_POST['user_id'];
          # Get Company 
          $user_id = $_POST['user_id'];
          $company = $this-&gt;load-&gt;model('usermanager_model', 'usermanager');
          $company_details[datas] = $this-&gt;usermanager-&gt;getCompany($user_id); 
  
          # Pass data to view
          $this-&gt;load-&gt;view('home_view', $company_details);
  
  }
  </code></pre>
  
  <p>And dont worry about my Model its working fine. 
  Here is my view </p>
  
  <pre><code>   &lt;div class="video-part"&gt;
      &lt;div class="video-details"&gt;
  
          &lt;div id="test"&gt;
          &lt;div id="mediaplayer"&gt;JW Player goes here&lt;/div&gt;
      &lt;?php  echo $url = vimeourl2videourl('http://vimeo.com/moogaloop.swf?clip_id=2539741') ?&gt;
      &lt;script type="text/javascript" src="&lt;?php echo base_url()?&gt;player1/jwplayer.js"&gt;&lt;/script&gt;
      &lt;div id="mediaplayer"&gt;JW Player goes here&lt;/div&gt;
  
      &lt;script type="text/javascript" src="jwplayer.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          jwplayer("mediaplayer").setup({
              flashplayer: "&lt;?php echo base_url() ?&gt;player1/player.swf",
                          height:"350",
                          width:"500",
              'playlist': [{
              'file': 'www.youtube.com/watch?v=dHBJ8jk3944', 
              'image': '/thumbs/video1.jpg',
              'title': 'The first video'
          },],
          repeat: 'list'           
          });
      &lt;/script&gt;
      &lt;/div&gt;
          &lt;div class="video-text"&gt;
  
              &lt;div id="company"&gt;
  
              &lt;?php 
              /*
              echo "&lt;pre&gt;";
               print_r($datas);
               echo "&lt;/pre&gt;";
                  */        
              foreach ($datas as $row) :
             echo $row['companyName']; 
             endforeach;
  
              ?&gt;
  
              &lt;/div&gt;
              &lt;span class="txt-small"&gt;2013-06-09  |  +011 888 88   |   Canada &lt;/span&gt;
              &lt;span class="txt-small"&gt;Lorem Ipsum is simply dummy text of the printing and typesetting industry. &lt;/span&gt;
              &lt;div class="social-icons row-fix"&gt;
                  &lt;a href="#"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;images/icon-down.png" alt=""&gt;&lt;/a&gt;
                  &lt;a href="#"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;images/icon-here.png" alt=""&gt;&lt;/a&gt;
                  &lt;a href="#"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;images/icon-wifi.png" alt=""&gt;&lt;/a&gt;
                  &lt;a href="#"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;images/icon-save.png" alt=""&gt;&lt;/a&gt;
                  &lt;a href="#"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;images/icon-facebook.png" alt=""&gt;&lt;/a&gt;
                  &lt;a href="#"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;images/icon-twitter.png" alt=""&gt;&lt;/a&gt;
                  &lt;a href="#"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;images/icon-google.png" alt=""&gt;&lt;/a&gt;
                  &lt;div class="sign-up row-fix"&gt;
                      &lt;a href="&lt;?php echo base_url().'registration';?&gt;"&gt;Signup&lt;/a&gt; &lt;span&gt;|&lt;/span&gt; &lt;a href="&lt;?php echo base_url().'registration';?&gt;"&gt;Login&lt;/a&gt;
                      &lt;div&gt; &lt;a href="#" class="request"&gt;Request for Product Info&lt;/a&gt;&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My problem is whenever I click image(On-click function) It will load my content with repeated html div tags. But If I print that data in my controller its working fine. Its correctly displayed fetched data only. If I pass that data to view and print then it will show the fetched data with some repeated div tags. My friend told me to use jQuery append function. But I am not familiar with jQuery. Please help to find out proper solution..? </p>