how to update div in other ctp file from another ctp file using Ajax?
I am using Ajax link to update div in my view page. Example : I have 2 ctp file say view1.ctp and
view2.ctp,开发者_如何学运维 I want to update the div in the view1.ctp using the ajax call in view2.ctp. Can anybody
give me the hint to resolve this issue
Thanks in advance Pushpa
you can use jQuery for a better approach.
eg:
<script type="text/javascript">
$.get('view2.ctp', function(data) {
$('#divview1').html(data);
});
</script>
and in view1.ctp
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
function loadData(){
$.get('view2.ctp', function(data) {
$('#divview1').html(data);
});
}
</script>
</head>
<body>
<div id="divview1"></div> <a href="#" onclick="loadData()">Load data from view2.ctp</a>
</body>
</html>
if you don't want to use jQuery you can use XMLHttpRequest, but jQuery is way more easier to use.
精彩评论