- 浏览: 497946 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (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 912见http://webin.us/chunterg/330 ... -
jQuery 1.5 的Deferred对象
2011-10-29 17:33 1070Jquery.Deferred对象是jquery1.5新引入的 ... -
利用HTTP-only Cookie缓解XSS之痛
2011-05-25 10:35 4472详细介绍请看: http://netsecurity.51ct ... -
用javascript来检测你在页面上的发呆时间(jquery插件)
2011-03-21 08:53 1308There are a few cases where you ... -
前端开发最佳实践与编程规范
2011-03-17 13:09 1069http://na.isobar.com/standards/ ... -
jquery1.5改进
2011-01-25 08:27 948jQuery1.5的改进细节 一小段jQuery代码的分析与优 ... -
Endless scroller jQuery plugin 到面面底部后在加载信息的插件
2010-12-21 08:56 1672http://pushingtheweb.com/2010/0 ... -
Reaching out of the browser sandbox using jQuery Title Alert. jquery插件tile提示来消息
2010-12-21 08:47 1238转自:http://pushingtheweb.com/201 ... -
jquery插件开发
2010-11-30 12:24 1075转自: http://www.cnblogs.com/from ... -
SQLike – a small query engine
2010-11-30 11:40 1657插件官方地址:http://www.thomasfrank.s ... -
sessvars插件中文文档----一款用window.name产生前台session存储的js插件
2010-11-30 11:27 1846转自: http://blog.csdn.net/lg ... -
CSS 中选择器的详解
2010-11-30 08:55 1115http://zachary-guo.iteye.com/bl ... -
【多浏览器的兼容问题】IE6.0、IE7.0 、FireFox 在样式中的不同写法
2010-11-30 08:54 1514原文出处:http://www.xianzheng.net.c ... -
JavaScript 面向对象程序设计
2010-11-30 08:17 1078近期在网上看到一篇关 ... -
jQuery 的原型关系图,让你快速对 jQuery 有个整体的把握
2010-11-30 07:51 951若干个月前,在博客园中看到一篇文章 ,内容很简单,就是一幅图 ... -
jquery 插件
2010-07-09 15:44 20490. 表单校验插件 http://www.position- ... -
jquery 几点笔记
2010-07-06 10:50 01. javascript里的函数和变量 在javascri ... -
ajax push
2009-12-24 08:56 3273很多应用譬如监控、即时通信、即时报价系统都需要将后台发生的变化 ... -
javascript学习收集
2009-04-22 08:49 1128YUI中文文档 http://www.blogjava.n ...
相关推荐
变化包括一个重写的Ajax模块,划分 jQuery子类的能力,以及许多其他功能增强,修复各种内存泄漏,性能改进和加强跨浏览器的兼容。鼓励测试该版本的用户提供反馈和报告他们遇到的任何错误。 该版本最大改进兼容IE9
其中 jquery-jquery-1.5-vsdoc.js可以为Visual Studio提供jquery1.5的智能提示。 jQuery 1.5.1 发布,全面支持IE9 jQuery 1.5.1发布了!这是自jQuery1.5发布以来第一个小版本更新,并且解决了很多BUG。 据jQuery...
这个1.5版本最大的更新是AJAX的完全重写,提供了更强的可扩展性。但是受制于精力和篇幅,对新的AJAX的分析还是放到下回,本篇先简单介绍一下细节方面的改进。 jQuery._Deferred和jQuery.Deferred 首先不得不说这两个...
假期里没事就想着改进下,改得地方不多,主要有以下三点: complete回调在jquery1.5以后可以是一个函数数组,按数组顺序调用。 如果前一个请求未返回,新的请求发出,那么撤销前一个请求,也就是新的请求“覆盖”原...
·attribute(改进了.attr()的性能)、jQuery()核心函数、CSS(.css()性能有两倍提升)、特效和事件、DOM操作等也有显著改进 1.5 美国时间1月31日John Resig在jQuery官方博客发表文章,宣布jQuery 1.5正式版已经...
$.sub:该方法是在jQuery 1.5中引入的,但是被证明不是很有用,将被移到jQuery 1.9兼容性插件中。 全局AJAX事件:一些事件(如ajaxStart)可以被附加到不在一个文档中的任何元素中,这将导致效率低下。在1.9中,...
$.sub:该方法是在jQuery 1.5中引入的,但是被证明不是很有用,将被移到jQuery 1.9兼容性插件中。 全局AJAX事件:一些事件(如ajaxStart)可以被附加到不在一个文档中的任何元素中,这将导致效率低下。在1.9中,Ajax...
4.支持使用jQuery实现Ajax分页,生成的Html代码更精简; 5.支持Ajax分页模式下,若客户端浏览器不支持或禁用Javascript功能时安全降级为普通分页 6.搜索引擎友好,无论是普通分页还是Ajax分页,搜索引擎都可以直接...
4.支持使用jQuery实现Ajax分页,生成的Html代码更精简; 5.支持Ajax分页模式下,若客户端浏览器不支持或禁用Javascript功能时安全降级为普通分页 6.搜索引擎友好,无论是普通分页还是Ajax分页,搜索引擎都可以直接...
4.支持使用jQuery实现Ajax分页,生成的Html代码更精简; 5.支持Ajax分页模式下,若客户端浏览器不支持或禁用Javascript功能时安全降级为普通分页 6.搜索引擎友好,无论是普通分页还是Ajax分页,搜索引擎都可以直接...
4.支持使用jQuery实现Ajax分页,生成的Html代码更精简; 5.支持Ajax分页模式下,若客户端浏览器不支持或禁用Javascript功能时安全降级为普通分页 6.搜索引擎友好,无论是普通分页还是Ajax分页,搜索引擎都可以直接...
6、修正了jQuery Ajax分页时生成的url中重复出现x-requested-width=的bug; 7、增加IPagedList 接口,HtmlHelper.Pager、HtmlHelper.AjaxPager和Ajax.Pager扩展方法第一个参数改为IPagedList,不再是PagedList; 8、...
《JavaScript基础教程(第8版)》循序渐进地讲述了JavaScript及相关的CSS、DOM、Ajax、jQuery等技术。书中从JavaScript语言基础开始,分别讨论了图像、框架、浏览器窗口、表单、正则表达式、用户事件和cookie,并在上...
1.5 小结 第2章 选择符 2.1 DOM 2.2 工厂函数$() 2.3 CSS选择符 2.4 属性选择符 2.5 自定义选择符 2.5.1 每隔一行为表格添加样式 2.5.2 基于表单的选择符 2.6 DOM遍历方法 2.6.1 为特定单元格添加样式 ...
11.3 Ajax的jQuery方式 334 11.3.1 使用load( )函数 335 11.3.2 教程:load( )函数 336 11.3.3 get( )和post( )函数 339 11.3.4 格式化发送给服务器的数据 341 11.3.5 处理来自服务器的数据 343 11.3.6 教程:使用...