这里放一些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. phalcon的CLI应用

    CLI应用是命令行下执行的程序, 可以应用于定时任务,守护进程, 脚本, 公用命令等等. 最小的目录结构:app/config/config.phpapp/tasks/MainTask.phpapp/ ...

  2. drupal 使用步骤

    一.安装 二.汉化 ①.下载语言包文件:http://localize.drupal.org/translate/languages/zh-hans ②.将 .po 文件放置到 drupal7/pro ...

  3. unicode编码转汉字

    String hexB = Integer.toHexString(utfBytes[byteIndex]);   //转换为16进制整型字符串 if (hexB.length() <= 2)  ...

  4. UML---UML中的几种关系(依赖,关联,泛化,实现)

    关于设计模式的总结没有落实到代码上,而且设计模式自己确实动手实现的非常少.所以在这一周里,除了看网站开发的视频,着手开始对设计模式进行实现以下.设计模式非常经典,每次看都有不同的收获,写一下自己的收获 ...

  5. (转)sqlite3生成lib遇到的问题

    今天想用一用sqlite,但是下载后发现只有DLL,没有LIB,只能自己生成了.在H:/Program Files/Microsoft Visual Studio 8/VC/bin里面有个lib.ex ...

  6. Linux Source命令及脚本的执行方式解析(转)

    当我修改了/etc/profile文件,我想让它立刻生效,而不用重新登录:这时就想到用source命令,如:source /etc/profile对source进行了学习,并且用它与sh 执行脚本进行 ...

  7. Unity3D之碰撞体,刚体

    一 概念介绍 刚体 Rigidbody(刚体)组件可使游戏对象在物理系统的控制下来运动,刚体可接受外力与扭矩力用来保证游戏对象像在真实世界中那样进行运动.任何游戏对象只有添加了刚体组件才能受到重力的影 ...

  8. NET Core 环境搭建和命令行CLI入门[转]

      NET Core 环境搭建和命令行CLI入门 时间:2016-07-06 01:48:19      阅读:258      评论:0      收藏:0      [点我收藏+]   标签: N ...

  9. 【mysql】恢复备份

    windows环境: 打开cmd cd 到备份数据目录 mysql -u*** -p use database; source *****.sql;

  10. 扩展方法和Lambda之练习手记

    扩展方法是我们日常开发当中所经常简化代码,提高性能和代码可读性的一个重要开发手段. 扩展方法是一个只能在静态类中声明的静态方法 Lambda 是一个表达式 ,学会了 可以使代码简洁,也是装13的利器. ...