这里放一些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. C语言 · 完美的代价

    基础练习 完美的代价   时间限制:1.0s   内存限制:512.0MB        锦囊1 使用贪心算法. 锦囊2 从左到右枚举每个字符,移动对应字符.个数为单的字符放中间.   问题描述 回文 ...

  2. hive中创建表失败

    使用create table命令创建表失败,如下错误信息: hive> create table test(id int,name string,age int,sex string); FAI ...

  3. [Django学习]上传图片

    上传图片 当Django在处理文件上传的时候,文件数据被保存在request.FILES FILES中的每个键为<input type="file" name="& ...

  4. iOS开发小技巧--取消按钮的选中状态

    首先要自定义按钮,并且实现如下方法,对,就是这么实现!!

  5. JavaScript(二):JavaScript语法及数据类型

    一.JavaScript语法 1.区分大小写ECMAScript中的一切,包括变量.函数名和操作符都是区分大小写的.例如:text和Text表示两种不同的变量.2.标识符所谓标识符,就是指变量.函数. ...

  6. java-事务-案例

    项目结构: 数据库: /* SQLyog Ultimate v12.09 (64 bit) MySQL - 5.5.53 : Database - threadlocal ************** ...

  7. 03 Files

    本章提要-----------------------------------------------组成 oracle 的 8 种主要文件(包括 instance 和 database)instan ...

  8. 第二百九十五节,python操作redis缓存-字符串类型

    python操作redis缓存-字符串类型 首先要安装redis-py模块 python连接redis方式,有两种连接方式,一种是直接连接,一张是通过连接池连接 注意:以后我们都用的连接池方式连接,直 ...

  9. (转)分析kernel的initcall函数

      分析kernel的initcall函数   来源: ChinaUnix博客 日期: 2008.07.19 21:24 (共有条评论) 我要评论   分析kernel的initcall函数Autho ...

  10. openal资料转贴

    地址:http://blog.sina.com.cn/s/blog_685b5b220100ukbp.html OpenAL简介 OpenAL(Open Audio Library)是专门负责3D定位 ...