日记整理---->2016-11-23
这里放一些jquery的学习知识。可能从一开始就是我一个人单枪匹马,来年不求并肩作战,只愿所向披靡。
jquery的学习一
jquery关于ajax的一些学习博客
ajax方法的介绍:https://learn.jquery.com/ajax/jquery-ajax-methods/ ajax方法jsonp:https://learn.jquery.com/ajax/working-with-jsonp/ jquery中deferreds:https://learn.jquery.com/code-organization/deferreds/ jquery的api学习:https://api.jquery.com/
jquery关于ajax的代码示例
一、我们通过一个案例来学习ajax的一些细节
- html的代码:
<input type="text" id="username">
<button onclick="ajaxTest()">click me</button>
- js的代码:
function ajaxTest() {
var username = $("#username").val();
var data = {
username: username
}
$.ajax({
url: "loginAction/userLogin.action",
data: data,
type: "GET"
}).done(function(response, textStatus, jqXHR ) {
console.log("done methods." + response);
console.log("textStatus " + textStatus);
}).fail(function( xhr, status, errorThrown ) {
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
}).always(function( xhr, status ) {
console.log( "The request is complete!" );
});
}
- java的代码:
@Controller
@RequestMapping(value = "loginAction")
public class LoginAction {
@RequestMapping(value = "userLogin")
public void userLogin(HttpServletRequest request, HttpServletResponse response) throws IOException, Exception {
String username = (String) request.getAttribute("username");
if (StringUtils.isEmpty(username) ) {
throw new RuntimeException();
} else if (username.equals("huhx")) {
request.getRequestDispatcher("/html/fail.html").forward(request, response);
} else if (username.equals("linux")){
response.sendRedirect("/BaseTest/html/redicect.html");
} else {
response.getWriter().write("Hello World");
}
}
}
二、我们看一下demo运行的效果:
、当username为空时,也就是用户没有输入: 顺序执行了fail方法和always方法,后台报错。 、当username为huhx时:顺序执行了done方法和always方法,done里面的response内容是fail.html的内容。 、当username为linux时,顺序执行了done方法和always方法,done里面的response内容是redicect.html的内容。 、当username为其它时,顺序执行了done方法和always方法,done里面的response内容是字符串Hello World。
三、关于上述几个方法,官方的说明:
- jqXHR.done(function(data, textStatus, jqXHR) {});
An alternative construct to the success callback option, refer to deferred.done() for implementation details. 200和302都会执行done方法。
- jqXHR.fail(function(jqXHR, textStatus, errorThrown) {});
An alternative construct to the error callback option, the .fail() method replaces the deprecated .error() method. Refer to deferred.fail() for implementation details.
- jqXHR.always(function(data|jqXHR, textStatus, jqXHR|errorThrown) { }); (added in jQuery 1.6)
An alternative construct to the complete callback option, the .always() method replaces the deprecated .complete() method.In response to a successful request, the function's arguments are the same as those of .done(): data, textStatus, and the jqXHR object. For failed requests the arguments are the same as those of .fail(): the jqXHR object, textStatus, and errorThrown. Refer to deferred.always() for implementation details.
- jqXHR.then(function(data, textStatus, jqXHR) {}, function( jqXHR, textStatus, errorThrown ) {});
Incorporates the functionality of the .done() and .fail() methods, allowing (as of jQuery 1.8) the underlying Promise to be manipulated. Refer to deferred.then() for implementation details.
Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are removed as of jQuery 3.0. You can use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
dom元素选择器
一、文档中id只能是唯一的,class可以多个存在。
<div id="huhxDiv" class="huhxclass">
<span class="huhxclass">Hello World</span>
</div>
<div id="huhxDiv" class="huhxclass">
<span>Hello World</span>
</div>
通知js获得的结果如下:
console.log($("#huhxDiv").length); // 1,只能得到第一个找到的匹配元素
console.log($(".huhxclass").length); //
console.log(document.getElementById("huhxDiv").length); // undefined,由于原生的div是没有length属性的
java中的一些小知识
一、String类的compare方法
String str1 = "Abc", str2 = "ACc";
System.out.println(str1.compareTo(str2));
具体的源代码如下:
public int compareTo(String anotherString) {
int len1 = value.length;
int len2 = anotherString.value.length;
int lim = Math.min(len1, len2);
char v1[] = value;
char v2[] = anotherString.value;
int k = 0;
while (k < lim) {
char c1 = v1[k];
char c2 = v2[k];
if (c1 != c2) {
return c1 - c2;
}
k++;
}
return len1 - len2;
}
二、关于Date类的一些用法
Date date1 = new Date(2015 - 1900, 1, 3, 13, 23, 45); // 2015年2月
Date now = new Date();
System.out.println(now.getTime() - date1.getTime());
System.out.println(now.compareTo(date1)); // 时间先后的比较-1
System.out.println(date1);
运行的效果如下:注意new Date()的第一个参数,需要减去1900。对于js,不需要减去1900的。
Tue Feb :: CST
关于Date类里面的compareTo方法,源代码如下:
public int compareTo(Date anotherDate) {
long thisTime = getMillisOf(this);
long anotherTime = getMillisOf(anotherDate);
return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
}
三、关于UUID的一些用法
UUID uuid = UUID.randomUUID();
String uuidStr = uuid.toString().replaceAll("-", "");
System.out.println(uuid.toString());
System.out.println(uuidStr);
运行的效果如下:
dec86160-d271-439b--4046bba2ad94
dec86160d271439b88254046bba2ad94
四、Calendar类的一些使用
按理说new Date(int, int, int)等方法已经废弃了,官方推荐使用的是Calendar。基础使用方法如下:
Calendar calendar = Calendar.getInstance();
calendar.set(2015, 1, 3, 13, 23, 34); // 这个和上面的时间设置是一样的
System.out.println(calendar.getTime().toString());
运行的效果为: Tue Feb 03 13:23:34 CST 2015
Calendar中提供了before和after方法来比较时间的先后,关于before方法的代码如下:
public boolean before(Object when) {
return when instanceof Calendar && compareTo((Calendar)when) < 0;
}
五、TimeUnit的使用
TimeUnit.MILLISECONDS.sleep(1000);
友情链接
日记整理---->2016-11-23的更多相关文章
- 【读书笔记】2016.11.19 北航 《GDG 谷歌开发者大会》整理
2016.11.19 周六,我们在 北航参加了<GDG 谷歌开发者大会>,在web专场,聆听了谷歌公司的与会专家的技术分享. 中午免费的午餐,下午精美的下午茶,还有精湛的技术,都是我们队谷 ...
- 2018.11.23 浪在ACM 集训队第六次测试赛
2018.11.23 浪在ACM 集训队第六次测试赛 整理人:刘文胜 div 2: A: Jam的计数法 参考博客:[1] 万众 B:数列 参考博客: [1] C:摆花 参考博客: [1] D:文化之 ...
- U3D笔记11:47 2016/11/30-15:15 2016/12/19
11:47 2016/11/30Before you can load a level you have to add it to the list of levels used in the gam ...
- 微信iphone7、 ios10播放视频解决方案 2016.11.10
2016.11.10日更新以下方法 微信最新出同层播放规范 即使是官方的也无法解决所有android手机的问题. 另外iphone 5 .5s 某些手机始终会弹出播放,请继续采用 “以下是老的解决办法 ...
- 最新的 cocoapods 安装与使用(2016.11)
cocoapods简介: cocoapods 是iOS的类库管理工具,可以让开发者很方便集成各种第三方库,而不用去网站上一个个下载,再一个个文件夹的拖进项目中,还得添加相关的系统依赖库.只需要安装好c ...
- 【转载】webstorm11(注册,激活,破解,码,一起支持正版,最新可用)(2016.11.16更新)
很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了 最近封的厉害仅作测试 选择 License ...
- Beta周第14次Scrum会议(11/23)【王者荣耀交流协会】
一.小组信息 队名:王者荣耀交流协会 小组成员 队长:高远博 成员:王超,袁玥,任思佳,王磊,王玉玲,冉华 小组照片 二.开会信息 时间:2017/11/23 17:02~17:14,总计12min. ...
- 第35次Scrum会议(11/23)【欢迎来怼】
一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文小组照片 二.开会信息 时间:2017/11/23 17:03~17:24,总计21min.地点:东北师 ...
- Murano Weekly Meeting 2016.08.23
Meeting time: 2016.August.23 1:00~2:00 Chairperson: Kirill Zaitsev, from Mirantis Meeting summary: ...
- github javascript相关项目star数排行榜(前30,截止2016.11.18):
github javascript相关项目star数排行榜(前30,截止2016.11.18): 前端开源框架 TOP 100 前端 TOP 100:::::https://www.awesomes. ...
随机推荐
- C语言 · 递归求二进制表示位数
算法训练 6-2递归求二进制表示位数 时间限制:10.0s 内存限制:256.0MB 问题描述 给定一个十进制整数,返回其对应的二进制数的位数.例如,输入十进制数9,其对应的二进制数 ...
- 常用sqoop操作
1. 关系型数据库到hive sqoop import --connect jdbc:mysql://localhost:3306/datahouse --username datahs --pass ...
- hadoop上线和下线节点
在运行中的ambari hadoop集中中动态添加或删除节点 1. 下线节点1) namenode节点上dfs.exclude文件,看配置文件怎么配置的,里每行添加一个服务器名,如我要下线server ...
- javascript 图片滚动
<div style="width:9999px;"> <ul id="marquePic1_1"> <li> <dl ...
- Hbase 学习(一) hbase配置文件同步
最近在狂啃hadoop的书籍,这部<hbase:权威指南>就进入我的视野里面了,啃吧,因为是英文的书籍,有些个人理解不对的地方,欢迎各位拍砖. HDFS和Hbase配置同步 hbase的配 ...
- 关于c# 发射的调用并进行缓存
private static object CreateObject(string AssemblyPath, string classNamespace) { object objObject = ...
- LINQ操作符二:SelectMany
SelectMany操作符提供了将多个from子句组合起来的功能,相当于数据库中的多表连接查询,它将每个对象的结果合并成单个序列. 示例: student类: using System; using ...
- 用isNaN函数来判断是否只能输入正负数字
isNaN() 函数通常用于检测 parseFloat() 和 parseInt() 的结果, 以判断它们表示的是否是合法的数字.当然也可以用 isNaN() 函数来检测算数错误,比如用 0 作除数的 ...
- thinkphp 操作mssql2008
配置文件 <?php return array( //'配置项'=>'配置值' //'USERNAME'=>'admin', //赋值 //数据库配置信息 'DB_TYPE' =&g ...
- 关于Cocos2d-x中增加暂停按钮的步骤
1.在GameScene.cpp的init方法中先定义一个里面放着可变换并在变换的时候会响应事件的MenuItem的Menu,这个Menu里面的可变换MenuItem又由两个小MenuItem组成,每 ...