我正在嘗試使用ajax刷新/重新載入頁面。Codeigniter中的Ajax問題
查看:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Insert | SP</title>
<script src="<?php echo base_url(); ?>bootstrap/js/jquery-2.1.1.min.js"></script>
腳本部分
<script>
$(document).ready(function(){
function loadNowPlaying(){
$(this).load('<?php echo base_url().'Store/student' ;?>');
}
setInterval(function(){loadNowPlaying()}, 5000);
});
</script>
重命名代碼
</head>
<body>
<form action="<?php echo base_url();?>Store/add" method="post">
<input type="text" name="name" id="name"><br>
<input type="text" name="mail" id="mail"><br>
<input type="password" name="pass" id="pass"><br>
<input type="submit" name="submit" id="submit" value="Insert">
</form>
<table id="studata">
<?php foreach ($students as $student):?>
<tr>
<th>Name</th>
<th>Email</th>
<th>Password</th>
</tr>
<tr>
<td><?php echo $student->Name;?></td>
<td><?php echo $student->Email;?></td>
<td><?php echo $student->Password;?></td>
</tr>
<?php endforeach;?>
</table>
</body>
</html>
我的控制器代碼:
public function student()
{
$data["students"] = $this->sp->getstudent();
$this->load->view('student',$data);
}
我的模型:
public function getstudent()
{
$this->db->select('*');
$this->db->from('ex_sp');
$query = $this->db->get();
return $query->result();
}
的代碼工作正常,但它加載了我的整個頁面[查看],我想只加載表或者一些特定的容器,但使用相同的視圖。我檢查了很多問題,但沒有找到我想要的,請檢查問題而不是投下。 它有什麼問題?有人可以看看它。
我不是在那裏看到任何Ajax。 – Difster
你正試圖從視圖本身加載視圖從jQuery加載函數? –
你的ajax代碼在哪裏? –