您的位置:首页 > 其它

ajax使用技巧之初入门

2016-05-31 15:03 316 查看
使用ajax可以局部刷新,开始自学的时候因为js也不是太好,所以总是感觉似懂非懂的,今天看了个视频,里面讲的不错,下面是我的心得笔记。

实现的效果是,可以把从后台得到的东西显示出来,局部刷新。

需要的文件:IndexAction.class.php index.html

IndexAction.class.php:

<?php

class IndexAction extends Action{

public function index(){

$this->display();

}

public function getAjax(){

$this->AjaxReturn('要返回的数据','信息',1);

}

}

?>

index.html:

<html>

<meta http-equiv="content-type" content="text/html;charset=utf-8" ">

<head><script src="__PUBLIC/js/jquery.js"></script></head>

<script>

$(function(){

$('button').bind('click',function(){

$.get('__uRL__/getAjax',function(jdata){

$('div#did').html(jdata.data);

})

})

});

</script>

<body>

<div id='did' style='background:pink;height:50px;width:100px'></div>

<button>点击</button>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: