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>
实现的效果是,可以把从后台得到的东西显示出来,局部刷新。
需要的文件: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>
相关文章推荐
- 定位
- ImageLoader
- python编程技巧2
- 机器学习&人工智能书籍
- 气动阀的性能检测
- grunt合并压缩js,css文件(第二弹)
- HTTPS请求步骤详解
- Android中的Bitmap和Drawable
- MOE建立ios调试环境
- 如何在Jupyter Notebook中使用Tensorflow
- FrameLayout中替换Fragment遇到异常java.lang.IllegalStateException: commit already called
- 使用mysqlsla分析mysql日志
- 第十四周项目1排序函数模板
- spring文件下载记录
- Exontrol - Editable Gantt ActiveX, NET, WPF Control (exg2antt)
- PHP 正则小解
- c# 进程间的通信实现之一简单字符串收发
- 类的成员函数
- How to Use Git and GitHub
- 应用调试之配置内核输出应用程序的段错误信息