<!DOCTYPE HTML>
<html lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var mydiv = $("#myDiv");
function swapContent(cv) {
// ajax請求時的等待圖片能夠寫在這裏
mydiv.html("
ut animated .gif here").show();
// 由於我調用這個視圖的和處理這個ajax的控制器是同一個,因此
// 可能會出現跨域錯誤
var u = "http://127.0.0.1/ci/index.php/test/ajax";
$.ajax({
type: "
OST",
url: u,
data: "name="+cv+'
&'+"<?php echo $this->security->get_csrf_token_name(); ?>"+'='+"
<?php echo $this->security->get_csrf_hash(); ?>",
success: function(msg){
mydiv.html(msg).show();
},
error: function() {alert("ajax error");}
});
}
$("#c1").click(function() {
swapContent("d1");
});
$("#c2").click(function() {
swapContent("d2");
});
$("#c3").click(function() {
swapContent("d3");
});
});
</script>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a id ="c1" href="#" >Content1
</a>
<a id = "c2" href="#" >Content2
</a>
<a id = "c3" href="#" >Content3
</a>
<div id="myDiv">My default content
</div>
</body>
</html>