愁人,编程语言这个东西,学完了能经常使用还好点,要是不经常使用的话,过不了几天就忘记用法了,这不昨天在本身练习用django学工具的时候,居然忘记了jquery中done的使用方法,可是却又很清楚的记得本身以前是用过的,就是想不起来,你说愁人不,写篇博客记录下吧。javascript
如下样例是在YII框架下写的,在CSRF_TOKEN的地方各类框架都不尽相同:css
<script type="text/javascript">html
$(document).ready(function(){java
$("#add").click(function(){jquery
var start = $("#start").val();django
var end = $("#end").val();编程
var CSRF_TOKEN = "<?= Yii::$app->getRequest()->getCsrfToken(); ?>";json
var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;app
var res = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;框架
if (!re.test(start)){
$("#status").html(" * ip地址格式不正确");
}else if (!res.test(end)){
$("#status").html(" * 输入不正确,请输入1-255之间的数字");
}else{
$.post('/hostmanager/addsystem/',
{
start:start,
end:end,
_csrf: CSRF_TOKEN
},null,'json').done(function(response){
if (response.status == 'RESULTS'){
var message= "<h3>" + response.message + "<h3>";
alertify.alert(message);
$(function() {
window.setTimeout(function(){
location.href="/hostmanager/";
}, 5000);
});
}else if (response.status == 'TESTCONN'){
var testconn = response.message;
document.write(testconn);
if(testconn == 1){
$('.exam').sibling('.light').css('background','green');
}else {
$('.exam').sibling('.light').css('background','red');
}
}else {
$("#status").html(" ");
}
});
};
});
});
</script>