- 浏览: 505575 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (200)
- java基础 (30)
- ajax (19)
- 乱写 (5)
- groovy (2)
- db (8)
- gwt (0)
- jee (2)
- 我关注的开源 (1)
- RIA AIR (1)
- spring (11)
- lucene (0)
- 工具 (10)
- 百科 (2)
- linux (6)
- android (40)
- 移动开发 (21)
- 代码片断 (15)
- tomcat (1)
- css (1)
- html5 (2)
- jquery (2)
- playframework (3)
- web (2)
- nio (3)
- design (1)
- nosql (3)
- 日志 (12)
- mysql (4)
- 图表 (1)
- python (3)
- ruby (1)
- git (0)
- hibernate (1)
- springboot (1)
- guava (1)
- mybatis (0)
- 工作问题 (3)
- php (1)
最新评论
-
linzm1990:
踩了很多坑啊。。。。
hibernate @Nofound 与@ManyToOne fetch lazy的问题 -
Ccccrrrrrr:
...
转: Spring boot 文件上传 -
rmzdb:
兄弟,你这个东西,在ie内核的浏览器,貌似不识别 文件名
工作问题:http下载文件,中文文件名在firefox下乱码问题 -
107x:
问题解决了,谢谢!
工作问题:http下载文件,中文文件名在firefox下乱码问题 -
klxqljq:
额鹅鹅鹅
android布局实现头尾固定, 中间多余内容可以滚动
源文见: http://api.jquery.com/extending-ajax/
相比之前的版本, 重写了ajax模块, 引入更多的扩展点. 三个概念:
Prefilters
A prefilter is a callback function that is called before each request is sent, and prior to any $.ajax() option handling.
Prefilters are registered using $.ajaxPrefilter(), and a typical registration looks like this:
It is also possible to attach a prefilter to requests with a specific dataType. For example, the following applies the given prefilter to JSON and script requests only:
Converters (注册自己的数据转换处理)
A converter is a callback function that is called when a response of a certain dataType is received while another dataType is expected.
Converters are stored into ajaxSettings and can be added globally as follows:
Converters are useful to introduce custom dataTypes. They can also be used to transform data into desired formats. Note: all custom dataTypes must be lowercase.
With the example above, it is now possible to request data of type "mydatatype" as follows:
或者也可以直接写在ajax单独的一次处理里
Transports (自定义整个的传输过程, 这是迫不得已才用)
A transport is an object that provides two methods, send and abort, that are used internally by $.ajax() to issue requests. A transport is the most advanced way to enhance $.ajax() and should be used only as a last resort when prefilters and converters are insufficient.
Since each request requires its own transport object instance, tranports cannot be registered directly. Therefore, you should provide a function that returns a transport instead.
Transports factories are registered using $.ajaxTransport(). A typical registration looks like this:
completeCallback has the following signature:
Just like prefilters, a transport's factory function can be attached to specific dataType:
The following example shows how a minimal image transport could be implemented:
Handling Custom Data Types
在jquery源码里, 已定义了几种处理类型
The jQuery Ajax implementation comes with a set of standard dataTypes, such as text, json, xml, and html.
Use the converters option in $.ajaxSetup() to augment or modify the data type conversion strategies used by $.ajax().
The unminified jQuery source itself includes a list of default converters, which effectively illustrates how they can be used:
When you specify a converters option globally in $.ajaxSetup() or per call in $.ajax(), the object will map onto the default converters, overwriting those you specify and leaving the others intact.
For example, the jQuery source uses $.ajaxSetup() to add a converter for "text script":
相比之前的版本, 重写了ajax模块, 引入更多的扩展点. 三个概念:
Prefilters
A prefilter is a callback function that is called before each request is sent, and prior to any $.ajax() option handling.
Prefilters are registered using $.ajaxPrefilter(), and a typical registration looks like this:
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) { // Modify options, control originalOptions, store jqXHR, etc });
- options are the request options
- originalOptions are the options as provided to the ajax method, unmodified and, thus, without defaults from ajaxSettings
- jqXHR is the jqXHR object of the request
It is also possible to attach a prefilter to requests with a specific dataType. For example, the following applies the given prefilter to JSON and script requests only:
$.ajaxPrefilter( "json script", function( options, originalOptions, jqXHR ) { // Modify options, control originalOptions, store jqXHR, etc });
Converters (注册自己的数据转换处理)
A converter is a callback function that is called when a response of a certain dataType is received while another dataType is expected.
Converters are stored into ajaxSettings and can be added globally as follows:
$.ajaxSetup({ converters: { "text mydatatype": function( textValue ) { if ( valid( textValue ) ) { // Some parsing logic here return mydatatypeValue; } else { // This will notify a parsererror for current request throw exceptionObject; } } } });
Converters are useful to introduce custom dataTypes. They can also be used to transform data into desired formats. Note: all custom dataTypes must be lowercase.
With the example above, it is now possible to request data of type "mydatatype" as follows:
$.ajax( url, { dataType: "mydatatype" });
或者也可以直接写在ajax单独的一次处理里
$.ajax( url, { dataType: "xml text mydatatype", converters: { "xml text": function( xmlValue ) { // Extract relevant text from the xml document return textValue; } } });
Transports (自定义整个的传输过程, 这是迫不得已才用)
A transport is an object that provides two methods, send and abort, that are used internally by $.ajax() to issue requests. A transport is the most advanced way to enhance $.ajax() and should be used only as a last resort when prefilters and converters are insufficient.
Since each request requires its own transport object instance, tranports cannot be registered directly. Therefore, you should provide a function that returns a transport instead.
Transports factories are registered using $.ajaxTransport(). A typical registration looks like this:
$.ajaxTransport( function( options, originalOptions, jqXHR ) { if( /* transportCanHandleRequest */ ) { return { send: function( headers, completeCallback ) { /* send code */ }, abort: function() { /* abort code */ } }; } });
- options are the request options
- originalOptions are the options as provided to the ajax method, unmodified and, thus, without defaults from ajaxSettings
- jqXHR is the jqXHR object of the request
- headers is a map of request headers (key/value) that the transport can transmit if it supports it
- completeCallback is the callback used to notify ajax of the completion of the request
completeCallback has the following signature:
function( status, statusText, responses, headers ) {}
- status is the HTTP status code of the response, like 200 for a typical success, or 404 for when the resource is not found.
- statusText is the statusText of the response.
- responses (Optional 可选) is a map of dataType/value that contains the response in all the formats the transport could provide (for instance, a native XMLHttpRequest object would set reponses to { xml: XMLData, text: textData } for a response that is an XML document)
- headers (Optional) is a string containing all the response headers if the transport has access to them (akin to what XMLHttpRequest.getAllResponseHeaders() would provide).
Just like prefilters, a transport's factory function can be attached to specific dataType:
$.ajaxTransport( "script", function( options, originalOptions, jqXHR ) { /* Will only be called for script requests */ });
The following example shows how a minimal image transport could be implemented:
$.ajaxTransport( "image", function( s ) { if ( s.type === "GET" && s.async ) { var image; return { send: function( _ , callback ) { image = new Image(); function done( status ) { if ( image ) { var statusText = ( status == 200 ) ? "success" : "error", tmp = image; image = image.onreadystatechange = image.onerror = image.onload = null; callback( status, statusText, { image: tmp } ); } } image.onreadystatechange = image.onload = function() { done( 200 ); }; image.onerror = function() { done( 404 ); }; image.src = s.url; }, abort: function() { if ( image ) { image = image.onreadystatechange = image.onerror = image.onload = null; } } }; } });
Handling Custom Data Types
在jquery源码里, 已定义了几种处理类型
The jQuery Ajax implementation comes with a set of standard dataTypes, such as text, json, xml, and html.
Use the converters option in $.ajaxSetup() to augment or modify the data type conversion strategies used by $.ajax().
The unminified jQuery source itself includes a list of default converters, which effectively illustrates how they can be used:
// List of data converters // 1) key format is "source_type destination_type" // (a single space in-between) // 2) the catchall symbol "*" can be used for source_type converters: { // Convert anything to text "* text": window.String, // Text to html (true = no transformation) "text html": true, // Evaluate text as a json expression "text json": jQuery.parseJSON, // Parse text as xml "text xml": jQuery.parseXML }
When you specify a converters option globally in $.ajaxSetup() or per call in $.ajax(), the object will map onto the default converters, overwriting those you specify and leaving the others intact.
For example, the jQuery source uses $.ajaxSetup() to add a converter for "text script":
jQuery.ajaxSetup({ accepts: { script: "text/javascript, application/javascript" }, contents: { script: /javascript/ }, converters: { "text script": jQuery.globalEval } });
发表评论
-
jquery 1.6新加功能
2011-10-29 17:36 949见http://webin.us/chunterg/330 ... -
jQuery 1.5 的Deferred对象
2011-10-29 17:33 1103Jquery.Deferred对象是jquery1.5新引入的 ... -
利用HTTP-only Cookie缓解XSS之痛
2011-05-25 10:35 4523详细介绍请看: http://netsecurity.51ct ... -
用javascript来检测你在页面上的发呆时间(jquery插件)
2011-03-21 08:53 1340There are a few cases where you ... -
前端开发最佳实践与编程规范
2011-03-17 13:09 1100http://na.isobar.com/standards/ ... -
jquery1.5改进
2011-01-25 08:27 972jQuery1.5的改进细节 一小段jQuery代码的分析与优 ... -
Endless scroller jQuery plugin 到面面底部后在加载信息的插件
2010-12-21 08:56 1698http://pushingtheweb.com/2010/0 ... -
Reaching out of the browser sandbox using jQuery Title Alert. jquery插件tile提示来消息
2010-12-21 08:47 1261转自:http://pushingtheweb.com/201 ... -
jquery插件开发
2010-11-30 12:24 1104转自: http://www.cnblogs.com/from ... -
SQLike – a small query engine
2010-11-30 11:40 1678插件官方地址:http://www.thomasfrank.s ... -
sessvars插件中文文档----一款用window.name产生前台session存储的js插件
2010-11-30 11:27 1880转自: http://blog.csdn.net/lg ... -
CSS 中选择器的详解
2010-11-30 08:55 1148http://zachary-guo.iteye.com/bl ... -
【多浏览器的兼容问题】IE6.0、IE7.0 、FireFox 在样式中的不同写法
2010-11-30 08:54 1549原文出处:http://www.xianzheng.net.c ... -
JavaScript 面向对象程序设计
2010-11-30 08:17 1103近期在网上看到一篇关 ... -
jQuery 的原型关系图,让你快速对 jQuery 有个整体的把握
2010-11-30 07:51 978若干个月前,在博客园中看到一篇文章 ,内容很简单,就是一幅图 ... -
jquery 插件
2010-07-09 15:44 20900. 表单校验插件 http://www.position- ... -
jquery 几点笔记
2010-07-06 10:50 01. javascript里的函数和变量 在javascri ... -
ajax push
2009-12-24 08:56 3312很多应用譬如监控、即时通信、即时报价系统都需要将后台发生的变化 ... -
javascript学习收集
2009-04-22 08:49 1161YUI中文文档 http://www.blogjava.n ...
相关推荐
jQuery 1.5版本是这个流行JavaScript库的一个重要里程碑,它包含了多项改进和新特性,旨在提高性能、增强功能和优化用户体验。以下是对jQuery 1.5版本类库的详细说明: 1. **核心性能提升**:jQuery 1.5在核心性能...
jQuery API 1.5是该库的一个重要版本,包含了丰富的功能和改进。下面我们将详细探讨jQuery 1.5中的关键知识点。 ### 1. 选择器(Selectors) jQuery 1.5对CSS选择器的支持更加完善,包括ID选择器(#id),类选择器(....
变化包括一个重写的Ajax模块,划分 jQuery子类的能力,以及许多其他功能增强,修复各种内存泄漏,性能改进和加强跨浏览器的兼容。鼓励测试该版本的用户提供反馈和报告他们遇到的任何错误。 该版本最大改进兼容IE9
jQuery1.5之后,$.param()函数改进了数据序列化,能更有效地处理复杂的数据结构,如对象和数组。同时,$.parseJSON()用于将JSON字符串转换为JavaScript对象,这在处理服务器返回的数据时非常有用。 ```javascript ...
4. **改进的选择器引擎**:jQuery 1.5在选择器引擎Sizzle上做了升级,增强了CSS3选择器的支持,使得开发者能更方便地使用复杂的选择器表达式。 5. **插件兼容性**:新版本保持了对现有插件的兼容性,确保开发者已有...
jQuery 1.5改进了动画功能,如`fadeIn()`, `fadeOut()`, `slideToggle()`等用于创建平滑的视觉效果。`animate()`方法允许自定义动画,控制CSS属性的变化。 5. **Ajax交互** jQuery的Ajax模块使得异步数据交互变得...
**jQuery 1.5** 是一个重要的JavaScript库版本,它在Web开发中广泛使用,尤其在简化DOM操作、事件处理、动画效果以及Ajax交互等方面。这个版本发布于2011年,带来了许多新功能和改进,使得前端开发更加高效和便捷。 ...
jQuery 1.5是这个库的一个重要里程碑,它引入了许多改进和新功能,极大地提升了JavaScript开发的效率和灵活性。这份中文说明文档详细解读了1.5版本中的所有更新,为开发者提供了宝贵的参考资料。 首先,jQuery 1.5...
首先,jQuery 1.5对AJAX模块进行了大幅度的改进。引入了Promise对象,这是基于 deferred 对象的进一步扩展,使得异步操作的管理更加灵活和可控。通过`.done()`, `.fail()`, 和 `.always()` 方法,开发者可以更清晰地...
3. **AJAX改进**:优化了AJAX请求的性能,支持JSONP和CORS(跨域资源共享),增强了AJAX请求的灵活性。 4. **动画优化**:动画效果更流畅,可以同时控制多个元素的动画,且提供更精确的控制选项。 5. **插件生态系统...
3. **改进的Ajax支持**:1.5版本加强了Ajax功能,提供了更好的错误处理和更灵活的配置选项。例如,全局Ajax事件和`$.ajaxStop()`等方法,使开发者能更好地控制异步请求的生命周期。 4. **更强大的选择器引擎**:...
3. **Ajax改进** - `$.ajax()`方法的`dataType`选项更加智能,能够自动检测服务器返回的数据类型。 - 引入了`$.Deferred`对象,增强了异步编程的能力,使得回调函数可以通过链式调用来管理。 4. **DOM操作** - `...
JQuery 1.5是该库的一个版本,它包含了多个重要的功能和改进: 1. **选择器增强**:JQuery 1.5支持更多的CSS3选择器,使得开发者能更方便地选取DOM元素。 2. **Deferred 和 Promises**:引入了 Deferred 对象和 ...
本文将深入探讨jQuery 1.5、1.6及1.7这三个重要版本中的关键特性、改进与最佳实践,旨在帮助开发者更高效地利用这些版本来提升项目性能和用户体验。 一、jQuery 1.5:Promise对象与 Deferred对象的引入 1.5版本...
1. jQuery 1.5:核心改进与新特性 - Deferred对象:1.5版本引入了Deferred对象,用于处理异步操作,如Ajax请求,使其更易于管理和链式调用。 - 兼容性提升:提升了与旧版IE浏览器的兼容性,同时优化了遍历和选择器...
在Web开发领域,jQuery 1.5是一个重要的版本,它带来了许多增强和改进。本文将深入探讨jQuery 1.5中文API的详细内容,以及如何利用其帮助文档进行学习和应用。 首先,让我们了解一下jQuery的核心概念。jQuery简化了...
jQuery 1.5版本中的亮点之一是改进了AJAX处理。通过增强$.ajax()函数,增加了更多的选项和回调,使得开发者能够更好地控制异步请求的流程。此外,Promise对象(表现为Deferred和Promise接口)的引入,使得链式调用变...
jQuery 1.5版本发布于2011年,带来了许多增强和改进,包括对Promise对象的增强、动画控制优化以及对CSS选择器的支持等。本文将围绕jQuery 1.5 API的核心功能进行详细解读。 1. **选择器(Selectors)** jQuery ...
1.5版本是jQuery历史上的一个重要里程碑,引入了许多改进和新功能,为开发者提供了更丰富的工具和选项。本参考手册将深入探讨jQuery 1.5的主要API和jQuery UI 1.5.1的相关内容。 ### jQuery核心API 1. **选择器**:...
**jQuery 1.5-1.85 版本详解** jQuery 是一款广泛使用的JavaScript库,它极大地简化了JavaScript的DOM操作、事件处理、动画设计和Ajax交互。从1.5到1.85,jQuery经历了一系列的更新与优化,为开发者提供了更强大的...