此篇依然与前一篇动态篇环境一样,基于jquery
转载前请贴上博客链接,谢谢:http://blog.youkuaiyun.com/gugugujiawei
一、表单提交(post的同步加载)
<form method="post" onSubmit="return check_recover()">
<a href="javascript:void(0)" id="allSelect2" >全部</a>
<a >-</a>
<a href="javascript:void(0)" id="noneSelect2" >无</a>
<a >-</a>
<input type="submit" class="btn btn-primary" name="recover" value="恢复所选"></input>
<button type="button" class="btn btn-primary">删除所选</button>
</form>
解释:当点击submit对应的按钮时,会直接提交到服务器,当此前为调用check_recover()函数,在这个函数中可以判断提交的内容是否合法,如果是则return true,则完成表单提交,实现同步加载。
二、ajax异步加载
<pre name="code" class="javascript">function post_message1(){
//alert('success')
data={'type':"2",'ip':'127.0.0.1'};
$.post($(this).attr('action'), data, function(data,status,xhr){
if(status=="success"){
change();
}
});
}
<pre name="code" class="javascript">function post_message2(){
$.getJSON("yoururl",function(data){
dosomething();
});
}
</pre><pre>
解释:
1、当调用post_message()函数时,发送data数据到服务器,当成功返回时,再调用change()函数。
2、当调用post_message()函数时,访问url为yoururl的链接,返回含有data数据的response,然后调用dosomething()函数。
三、刷新当前页面
<pre name="code" class="javascript">window.location.reload();
四、定时执行某些特定操作,譬如更新图
<pre name="code" class="javascript">$(function () {
window.setInterval('hostusage()', 2000);
});
解释:两秒调用hostusage()函数一次