我的 Codeigniter 应用程序有问题。我想通过ajax加载一些数据。在我的页面中,我编写了 onclick 函数来运行 jQuery 函数。在我的函数中,我只是将该响应发布到我的控制器。这是我的 jQuery 函数
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);
}
}
});
}
这是我的 loadVideo 功能(我的控制器)
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);
}
不要担心我的模型工作正常。这是我的看法
<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>
我的问题是每当我单击图像(单击功能)时,它都会使用重复的 html div 标签加载我的内容。但是,如果我在控制器中打印该数据,它工作正常。它仅正确显示获取的数据。如果我将该数据传递给查看和打印,那么它将显示带有一些重复 div 标签的获取数据。我的朋友告诉我使用 jQuery 追加功能。但我不熟悉 jQuery。请帮助找出正确的解决方案..?