1

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..?

7
  • What is the code in your home_view file? It should only echo out the company details and nothing else. Commented Oct 11, 2013 at 12:52
  • how does this line of code not throw a notice for you: $company_details[datas] ... you're missing quotes there Commented Oct 11, 2013 at 12:55
  • PHP will throw a notice and assume 'datas', so it works and OP might not even see the notice depending on his error reporting. It can end up ugly quick if it is also a constant so one should always use quotes. Commented Oct 11, 2013 at 13:00
  • @WebNovice I have included my view page.. Please checkout.. Commented Oct 11, 2013 at 13:22
  • @ZathrusWriter I changed to $company_details['datas']..But still no luck.. Commented Oct 11, 2013 at 13:24

1 Answer 1

2

Your home_view view file should have only the minimal HTML markup needed for that company details so that the output will be loaded inside the #cointainer div.

If your view file has HTML codes for a full page, that full page HTML will be loaded inside that #container div, and you get repeated divs

Your view file should have just the below:

<div id="company"> <?php foreach ($datas as $row) : echo $row['companyName']; endforeach; ?> </div> 
Sign up to request clarification or add additional context in comments.

1 Comment

Yes..!Thanks for your help.. Finally I got it.. The view page should contain only company div tag..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.