我是codeigniter的新手,我想只更改页面内容而不刷新页面。使用ajax但无法加载视图。
视图 -
<div class="tb-detail">
<a href="" class="logos">Click to change</a>
<form action="" method="post">
<div class="success_message"></div>
<div class="tb-detail-inner" id="general">
<label>Logo</label>
<input type="file" name="images">
<span>Upload the logo</span>
<textarea class="slogon"></textarea>
<span class="help-block">Change the slogon</span>
</div>
<div><button>Save</button></div>
</form>
</div>
我希望具有类tb-detail-inner的div的内容应该随着另一个视图(徽标)的内容而改变。为此,我写了一个看起来像这样的脚本 -
<script type="text/javascript">
$(document).ready(function() {
var base_url = '<?php echo base_url(); ?>';
$(".logos").click(function() {
$.ajax({
type: "POST",
url: base_url + 'index.php/panal/logos',
dataType:'html',
statusCode: {
404: function() {
$(".tb-detail-inner").html('Could not contact server.');
},
500: function() {
$(".tb-detail-inner").html('A server-side error has occurred.');
}
},
error: function() {
$(".tb-detail-inner").html('A problem has occurred.');
},
success: function(data) {
$(".tb-detail-inner").html(data);
console.log(data);
}
});
});
});
</script>
和控制器是 -
<?php
class Panal extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index() {
$this->load->view('setting/logo');
}
public function logos() {
$this->load->view('setting/logo');
}
}
此面板控件具有加载logo.php视图的方法徽标。我想用logo.php视图更改内容
答案 0 :(得分:0)
尝试在第二个参数
中使用empty string
代替null
public function logos(){
echo $this->load->view('setting/logos', '', true);
}