这里放一些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">&nbsp;&nbsp;
<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的更多相关文章

  1. 【读书笔记】2016.11.19 北航 《GDG 谷歌开发者大会》整理

    2016.11.19 周六,我们在 北航参加了<GDG 谷歌开发者大会>,在web专场,聆听了谷歌公司的与会专家的技术分享. 中午免费的午餐,下午精美的下午茶,还有精湛的技术,都是我们队谷 ...

  2. 2018.11.23 浪在ACM 集训队第六次测试赛

    2018.11.23 浪在ACM 集训队第六次测试赛 整理人:刘文胜 div 2: A: Jam的计数法 参考博客:[1] 万众 B:数列 参考博客: [1] C:摆花 参考博客: [1] D:文化之 ...

  3. 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 ...

  4. 微信iphone7、 ios10播放视频解决方案 2016.11.10

    2016.11.10日更新以下方法 微信最新出同层播放规范 即使是官方的也无法解决所有android手机的问题. 另外iphone 5 .5s 某些手机始终会弹出播放,请继续采用 “以下是老的解决办法 ...

  5. 最新的 cocoapods 安装与使用(2016.11)

    cocoapods简介: cocoapods 是iOS的类库管理工具,可以让开发者很方便集成各种第三方库,而不用去网站上一个个下载,再一个个文件夹的拖进项目中,还得添加相关的系统依赖库.只需要安装好c ...

  6. 【转载】webstorm11(注册,激活,破解,码,一起支持正版,最新可用)(2016.11.16更新)

    很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了 最近封的厉害仅作测试 选择 License ...

  7. Beta周第14次Scrum会议(11/23)【王者荣耀交流协会】

    一.小组信息 队名:王者荣耀交流协会 小组成员 队长:高远博 成员:王超,袁玥,任思佳,王磊,王玉玲,冉华 小组照片 二.开会信息 时间:2017/11/23 17:02~17:14,总计12min. ...

  8. 第35次Scrum会议(11/23)【欢迎来怼】

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文小组照片 二.开会信息 时间:2017/11/23 17:03~17:24,总计21min.地点:东北师 ...

  9. Murano Weekly Meeting 2016.08.23

    Meeting time: 2016.August.23 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summary: ...

  10. github javascript相关项目star数排行榜(前30,截止2016.11.18):

    github javascript相关项目star数排行榜(前30,截止2016.11.18): 前端开源框架 TOP 100 前端 TOP 100:::::https://www.awesomes. ...

随机推荐

  1. DataGridView使用技巧十三:点击列头实现升序和降序排序

    DataGridView 列有三种排序模式.每一列的排序模式是通过该列的 SortMode 属性指定的,该属性可以设置为以下的 DataGridViewColumnSortMode 枚举值之一. Da ...

  2. FATAL ERROR: Could not find ./bin/my_print_defaults 解决方法

    FATAL ERROR: Could not find ./bin/my_print_defaults If you compiled from source, you need to run 'ma ...

  3. 关于Unity中的帧动画组件的编写

    一.帧动画 1: 美术准备好一个连续动作的离散图片;2: 程序在准确的时间来切换这个图片;3: 优点: 简单,速度快; 缺点:资源占用相对过大; 二.frame_anim组件编写 1: 代码里面强制要 ...

  4. Mastering the game of Go with deep neural networks and tree search浅析

    Silver, David, et al. "Mastering the game of Go with deep neural networks and tree search." ...

  5. 一遍记住Java常用的八种排序算法与代码实现

    1.直接插入排序 经常碰到这样一类排序问题:把新的数据插入到已经排好的数据列中. 将第一个数和第二个数排序,然后构成一个有序序列 将第三个数插入进去,构成一个新的有序序列. 对第四个数.第五个数……直 ...

  6. imx6 android power off

    调试android4.2的关机功能,希望再按下power按键长时间之后就关机.不弹出选框. 参考链接 http://www.cnblogs.com/sardine/archive/2011/07/26 ...

  7. php -- or 的用法

    经常看到这样的语句: $file = fopen($filename, r) or die("抱歉,无法打开: $filename"); or 在这里是这样理解的,因为在PHP中并 ...

  8. cake build使用:

    开源地址: https://github.com/cake-build/cake 依赖 powershell 3.0 Windows 获取引导程序: Invoke-WebRequest http:// ...

  9. 深入new/delete:Operator new的全局重载

    Operator new 的全局重载 原文地址:http://blog.csdn.net/zhenjing/article/details/4354880 我们经常看到这么一句话: operator ...

  10. apache Storm学习之三-消息可靠性

    4.1 简介 storm可以确保spout发送出来的每个消息都会被完整的处理.本章将会描述storm体系是如何达到这个目标的,并将会详述开发者应该如何使用storm的这些机制来实现数据的可靠处理. 4 ...