微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AjaxFilter

程序名称:AjaxFilter

授权协议: 未知

操作系统: 未知

开发语言:

AjaxFilter 介绍

This tiny plugin provides a registry for different filter functions to
sanitize ajax responses.
It requires jQuery 1.3 with its new feature, the ‘dataFilter’ ajax
setting.

If you want to provide a new implementation, you need to do something like
this:

jQuery.ajaxFilter.register( 'js_in_href', 'html', function( data ){ return data.replace(/href="javascript:[^"]+"/g, ''); });

or

jQuery.ajaxFilter.register('eval', 'script html json', function( data ){ return data.replace(/eval\(.+?\);?/g, ''); });

Arguments for jQuery.ajaxFilter.register() are:

  1. Name for the filter, used as ‘filter’ when calling jQuery.ajax.
  2. One or more dataTypes to handle. Can be any combination of ajax, html, json and xml separated by spaces.
  3. The filter function. Will receive 2 arguments: the data and the type. The ‘this’ will reference the settings object.

To use it, you do:

jQuery.ajax({ url:'foo.html', filter:'js_in_href', // ... });

The filter can also parse the response.
That means it can (for example) provide an alternative way of eval’ing json.
This is specially useful for Adobe AIR apps.
If the filter returns something else than a string, it’s assumed to be the
final response.

AjaxFilter 官网

http://plugins.jquery.com/project/AjaxFilter

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐