短小强悍的JavaScript异步调用库

转自伯乐在线

原文出处: krasimirtsonev   译文出处: 铁锚。欢迎加入技术翻译小组

20行完成一个JavaScript模板引擎》的备受好评我感到很惊讶,并决定用此文章介绍使用我经常使用的另一个小巧实用的工具。我们知道,在浏览器中的 JavaScript 绝大部分的操作都是异步的(asynchronous),所以我们一直都需要使用回调方法,而有时不免陷入回调的泥淖而欲死欲仙。

阅读更多

如何忘记jQuery而换用原生的JavaScriptAPI

 

转自github.com/roman01la

How to forget about jQuery and start using native JavaScript APIs

JavaScript is here and it’s ready for you, but probably you are not ready for it yet. Why not using jQuery? Because it’s slow and your website doesn’t really need extra weight.I’m not going to argue about libs vs native. Sometimes it’s really hard to live without all that magic stuff. But I’m going to argue about loading kilos of code just only for a one-character-selector-function aka $ or things like that.Assuming that shorthands is not the case, everyone use jSomething because of it’s support for IE, animation handling and the only selector function.

阅读更多

jQuery的getJSON方法post数据时自动添加的下划线字段

这两天在研究模拟登陆网盘。其中遇到一个问题,需要模拟发送一个POST,但是检测HTTP数据通信发现在发送时,经过POST发送的字段总是比form内的字段多一个下划线字段。一开始百思不得其解,后来经过仔细观察,发现这个字段的数值是一个数值,隐约感觉非常像json的时间字段,精确到毫秒的ticks。经过转换发现确实是标示发送时间的字段。

下划线字段的含义解决了,那它究竟是谁添加的呢?

在阅读发送这段内容的源代码后发现,这段代码是由jQuery的getJSON方法发送的,而且在发送前,已经使用ajaxSetup方法配置成异步、不缓存。阅读了jQuery的Refference后,发现默认就是异步,但是缓存为true。所以料想添加的下划线字段应该是用精确到毫秒的时间字段来将url标识为独一无二的请求,从而强制服务器发送最新的数据。

至此下划线问题完美解决:它是jQuery的ajax方法在设置为不缓存时自动添加的时间字段。