日记整理---->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#】实现依赖注入
1. 问题的提出 开发中,尤其是大型项目的开发中,为了降低模块间.类间的耦合关系,比较提倡基于接口开发,但在实现中也必须面临最终是“谁”提供实体类的问题.Martin Fowler在<Inver ...
- ThreadStart中如何带参数
1.ThreadStart 线程执行带参数的方法,new Thread(new ThreadStart(delegate { ThreadTask(firstPage, lastPage); })); ...
- win10计算机打开不要是“快速访问”功能?
win10的文件夹选项中---常规--最上端调整
- (转) eclipse安装lombok
lombok的官方网址:http://projectlombok.org/ 1. lombok的安装: 使用lombox是需要安装的,如果不安装,IDE则无法解析lombox注解,有两种方式可以安装l ...
- LUA中获得服务器IP
local t = {} -- 引入相关包local socket = require("socket") function t.main() local a,b=pcall(t. ...
- cause: java.lang.IllegalStateException: Serialized class com.taotao.pojo.TbItem must implement java.io.Serializable
HTTP Status 500 - Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: ...
- java设计模式——多例模式
★ 缓存在单例中的使用 缓存在编程中使用很频繁,有着非常重要的作用,它能够帮助程序实现以空间换取时间,通 常被设计成整个应用程序所共享的一个空间,现要求实现一个用缓存存放单例对象的类. 说明:该 ...
- Eclipse最经常使用快捷键总结
1. ctrl+shift+r:打开资源 这可能是全部快捷键组合中最省时间的了. 这组快捷键能够让你打开你的工作区中不论什么一个文件,而你仅仅须要按下文件名称或mask名中的前几个字母,比方appl ...
- gen_server的模板
-module(first_gen_server).-behaviour(gen_server).-export([init/1, handle_call/3, handle_cast/2, hand ...
- 弹窗插件zDialog使用教程
1.首先现在好zDialog然后复制项目中 2.配置zDialog解压以后images文件夹位置 images存放位置根据自己实际项目而定,zDialog.js中配置位置即可,如: var IMAGE ...