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
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); } } }); } And here is my loadVideo function ( My controller )
function loadVideo(){ $user_id = $_POST['user_id']; # Get Company $user_id = $_POST['user_id']; $company = $this->load->model('usermanager_model', 'usermanager'); $company_details[datas] = $this->usermanager->getCompany($user_id); # Pass data to view $this->load->view('home_view', $company_details); } And dont worry about my Model its working fine. Here is my view
<div class="video-part"> <div class="video-details"> <div id="test"> <div id="mediaplayer">JW Player goes here</div> <?php echo $url = vimeourl2videourl('http://vimeo.com/moogaloop.swf?clip_id=2539741') ?> <script type="text/javascript" src="<?php echo base_url()?>player1/jwplayer.js"></script> <div id="mediaplayer">JW Player goes here</div> <script type="text/javascript" src="jwplayer.js"></script> <script type="text/javascript"> jwplayer("mediaplayer").setup({ flashplayer: "<?php echo base_url() ?>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' }); </script> </div> <div class="video-text"> <div id="company"> <?php /* echo "<pre>"; print_r($datas); echo "</pre>"; */ foreach ($datas as $row) : echo $row['companyName']; endforeach; ?> </div> <span class="txt-small">2013-06-09 | +011 888 88 | Canada </span> <span class="txt-small">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span> <div class="social-icons row-fix"> <a href="#"><img src="<?php echo base_url() ?>images/icon-down.png" alt=""></a> <a href="#"><img src="<?php echo base_url() ?>images/icon-here.png" alt=""></a> <a href="#"><img src="<?php echo base_url() ?>images/icon-wifi.png" alt=""></a> <a href="#"><img src="<?php echo base_url() ?>images/icon-save.png" alt=""></a> <a href="#"><img src="<?php echo base_url() ?>images/icon-facebook.png" alt=""></a> <a href="#"><img src="<?php echo base_url() ?>images/icon-twitter.png" alt=""></a> <a href="#"><img src="<?php echo base_url() ?>images/icon-google.png" alt=""></a> <div class="sign-up row-fix"> <a href="<?php echo base_url().'registration';?>">Signup</a> <span>|</span> <a href="<?php echo base_url().'registration';?>">Login</a> <div> <a href="#" class="request">Request for Product Info</a></div> </div> </div> </div> </div> </div> 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..?
home_viewfile? It should only echo out the company details and nothing else.$company_details[datas]... you're missing quotes there