- 浏览: 157876 次
- 性别:
- 来自: 重庆
文章分类
最新评论
-
坏猪猪:
Document doc = Jsoup.connect(ur ...
android中jsoup解析html的几个例子 -
我很温柔但是不丑:
你好。看了您的例子,实践了一下,有问题啊?没有解析出来数据?怎 ...
android中jsoup解析html的几个例子
Get 工具提供了一个,在页面加载完之后,附加脚本和css资源(包括跨域资源)到DOM上的机制。
Get工具两种常见的用例:
1.跨站数据检索:因为XMLHttplRequest(YUI IO Utility也是使用XMLHttpRequest)依靠一个严格的同源策略,所以,要通过XHR检索第三方数据需要一个服务器代理。(具体搜索一下XMLHttpRequest工作原理)。如果是能控制或者完全信任的跨域资源,可以不通过服务端代理而直接加载 script 数据从不同源的地方;而 script 文件,可能是典型 json 格式化的数据,在 load 的时候会立马执行。有一点至关重要,如果你加载的 script file 有恶毒的代码,没有安全的机制可以保证用户不受到恶毒代码的影响,因为浏览器会以完全的权限来执行这些代码。所以记住这一点:不要让用户接触到那些不能彻底信任的数据源。
2.逐步加载方法:在富客户端应用中,基于用户动态加载需要的 js 文件和 css 文件变得非常有用, Get utility 提供了动态加载资源的功能。(注意:如果是加载 YUI 里面资源,可以使用 YUI loader 来加载, YUILoader 使用 Get Utility 来加载 YUI 组件,并且对解决 YUI 组件依赖问题) 。
开始
配置一个Get Utility 事务(Configuring a Get Utility Transaction。请问如何翻译?)
使用提供给你的回调函数的参数.
Getting Started
Configuring a Get Utility Transaction
Making Use of Arguments Supplied to Your Callback
Using the Get Utility to Insert Script Nodes
Using the Get Utilty to Insert CSS Files
Using JSONP Web Services
How is the Get Utility Different From IO?
YUI on Mobile Devices
开始
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>;
你可以取得一个脚本(Y.Get.script())and/or CSS(Y.Get.css())资源到页面。script和css方法都有一下参数:
1.URL(s):指定你需要加载到页面的URL(s), URL(s)可能是字符串或者字符串数组。
2.options:一个可选的配置对象,它包含了transaction(交互?)的信息;更多内容下面会讲到。
一个简单的文件请求可能如下:
YUI().YUI().use(function(Y) { var url = http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?" + "appid=3wEDxLHV34HvAU2lMnI51S4Qra5m.baugqoSv4gcRllqqVZm3UrMDZWToMivf5BJ3Mom" + "&results=20&output=json&omit_inlinks=domain" + "&callback=YAHOO.example.SiteExplorer.callback" + "&query=http://developer.yahoo.com/yui/", obj = Y.Get.script(url, { onSuccess: function() { alert("file loaded"); }; }); // 'obj'将是一个只有一个成员的对象,tID, //它是transaction中的唯一身份标识符, //它具有以下格式:"q0","q1","q2"..."qn" will be an object with a });
配置Get Utility Transaction
通过第二个参数配置script和css方法,这个可选的参数包含一个对象,这个对象包含以下字段:
配置选项
目的作用
onSuccess
(function) Callback method invoked by Get Utility when the requested file(s) have loaded successfully.
onFailure
(function) Callback method invoked by Get Utility when an error is detected or
abort
is called.
onProgress
(function) Callback method invoked by Get Utility after each node is inserted.
onTimeout
(function) Callback method invoked by Get Utility if a timeout is detected.
onEnd
(function) Callback method invoked by Get Utility when a transaction completes no matter how the transaction ended.
attributes
(object) A hash of attributes to apply to the dynamically created nodes. You might use this to add media="print" to a css file, for example.
win
(window) The
window
into which the loaded resource(s) will be inserted. Default: Y.config.win
.
context
(object) The execution context in which all callbacks will run. Default: the current
YUI
instance.
data
(any) Data to pass as an argument to
onSuccess
or onFailure
callbacks. Default: null
.
autopurge
(boolean) If set to true, script nodes will automatically be removed every 20 transactions (this number is globally configurable via the
Y.Get.PURGE_THRESH
property); script nodes can be safely removed in most cases, as their contents (having executed) remain available. CSS nodes should not have this set to true as it will remove the CSS rules. Default: true
for script nodes, false
for CSS nodes.
timeout
(int) Number of milliseconds to wait for a script to finish loading before timing out
使用提供给回调函数的参数
正如上面部分,你的回调函数(无论是onSuccess还是onFailure),能够使用提供给配置对象的data 成员(将如你已经在configuration中提供了一个这样的data成员—如上表格)。当然,并不是只有data这一成员可以使用,下面的成员也可以使用:
(说简单点就是,在onSuccess或者onFailure函数中,允许使用下面的参数:)
FIELD
CONTENTS
tId
(string) The unique identifier for this transaction; this string is available as the
tId
member of the object returned to you upon calling the script
or css
method.
data
(any) The
data
field you passed in your configuration object when the script
or css
method was called. Default: null
.
nodes
(array) An array containing references to node(s) created in processing the transaction. These will be script nodes for JavaScript and link nodes for CSS.
win
(window) The window object in which the nodes were created.
purge()
(function) Calling the returned
purge()
method will immediately remove the created nodes. This is safe and prudent for JavaScript nodes, which do not need to persist. If CSS nodes are purged, the rules they contain are no longer available and the page will repaint accordingly.
使用Get Utility插入脚本节点 var successHandler = function(o) { //o,包含了上表中所有描述的域。 o.purge(); //在执行之后立即移除script脚本节点。 Y.log(o.data); //传递给配置对象的data成员 } var objTransaction = Y.Get.script("http://json.org/json.js", { onSuccess: successHandler, data: { field1: value1, field2: value2 } })
当使用Y.Get.script()方法增加一个或者多个脚本文件到页面上时,Get Utility 按照以下步骤执行:
1.将一个脚本节点加载到请求脚本文件的目标窗口
2.将新脚本的src属性设置为指定的URL
3.如果transaction成功,脚本被加载执行。
4.脚本节点的load时间被激发
5.Get Utility检查是否有更多的URL,如果有,将返回第一步。
6.如果这个最后一个,Get Utility将唤醒onSuccess回调函数(如果指定了一个回调函数)
如下:
var handlerData = { //传递给success or failure句柄的数据。 //就像上面的。 }; var successHandler = function(oData) { //code to execute when all requested scripts have been //loaded; this code can make use of the contents of those //scripts, whether it's functional code or JSON data. }; var aURLs = [ "/url1.js", "/url2.js", "/url3.js" //等等。。。 ]; Y.Get.script(aURLs, { onSuccess: successHandler, data: handlerData });
使用Get Utility 来插入CSS文件
当你使用使用Y.Get.css()方法来增加一个或者多个CSS文件到页面上时,Get Utility 遵循以上脚本步骤。在Firefox和Safari上不兼容。
使用JSONP Web Services
Get Utility 和IO的区别
发表评论
-
yui3:widget 例子_widget-extend
2011-06-26 16:07 2569<!DOCTYPE HTML PUBLIC &qu ... -
yui3:widget
2011-06-18 11:36 3234Widget 类包含什么? widget类的结构和 ... -
YUI3:node2
2011-06-18 11:23 1YUI的Node功能为获取、 ... -
YUI3:plugin
2011-06-18 10:22 1435插件让你可以无侵入地 ... -
YUI3:Base
2011-06-16 20:39 1539Base类被设计成基础类 ... -
YUI3:Attribute
2011-06-16 10:30 1492YUI的Attribute功能允 ... -
YUI 3:Event
2011-06-15 22:23 15291. 要使用Event,首先要引入YUI3的种子文件: &l ... -
YUI3:Node
2011-06-15 15:59 2142YUI的Node功能为获取、创建、操作DOM节点提供很易懂的方 ... -
yui3 :Get 例子
2011-06-15 15:43 1292Getting a Script Node with JSON ... -
YUI:globle object
2011-06-13 11:52 1638YUI模块是YUI3中的单一核 ... -
YUI3:DataSource
2011-06-12 21:53 1245DataSource 工具,通过广泛支持的协议,为从不同的资源 ... -
YUI3:DataSchema
2011-06-12 20:57 886DataSchema Utility 应用一个给定的模式 ,以 ... -
YUI3:Cooke
2011-06-12 16:43 1198YUI Cookie工具为与cookies ... -
yui3 :datatype
2011-06-12 12:02 2058DataType工具为数据, ... -
YUI3:cache
2011-06-12 10:14 1235Cache 工具为存储名值对到本地JavaScript内存提供 ... -
YUI 3 周边
2011-06-11 16:46 10771.跨域请求:cross-domain 初步体验“AJAX不 ... -
YUI 3 :IO
2011-06-10 11:46 2887YUI IO是一个通讯工具,用于数据获取和内容更新,它使用X ... -
YUI 3 : json
2011-06-09 15:37 2626JSON (JavaScript Object ...
相关推荐
该版本的主要亮点包括:在Node.js中YUI可作为NPM模块正式引入了第2套皮肤“night”引入了App、Button、CSSButton、Handlebars、Pjax和TestConsole等组件重构了CSS网格,现在更加轻量级、灵活重构了Get,以支持更多的...
Express YUI 是 YUI 应用的 Express 扩展。示例代码:var express = require('express')...app.get('/foo', expyui.expose(), function (req, res, next) { res.render('foo'); }); 标签:Express
Express 框架是后台的 Node 框架,所以和 jQuery、zepto、yui、bootstrap 都不一个东西。 Express 在后台的受欢迎的程度类似前端的 jQuery,就是企业的事实上的标准
function onshengchange(e) { var sheng = Y.Node.get(‘#’+config.sheng).get(“value”); var speccode = Y.Node.get(‘#’+config.speciality); var years = Y.Node.get(‘#’+config.years); var timesli
需要把“1”改成中文汉字: 在 done方法里面进行数据渲染: layui.use('table', function()... method: 'post', //默认:get请求 cellMinWidth: 80, page: true, request: { pageName: 'pageNum', //页码的参数名
This book is for web developers who want to get straight into JavaScript and explore the tools and productivity gains offered by the frameworks. A working knowledge of HTML, CSS, and JavaScript are ...
效果 动态生成header 返回的header数据:格式为数组,因为是二级表头,所以是二元数组 后台动态拼接数组,返回数组后把两个数组push到一个空数组中就可以组成一个动态的多级表头 ... type: get,
gometa是一个基于go的元数据编程框架,很适合做企业应用软件开发。 gometa目标是让用户通过简单地配置即可完成增删改查功能,而专注于业务逻辑的编写和开发。 当前,gometa支持 1.数据库:MongoDB ...3.godec,(g
今天小编就为大家分享一篇解决使用layui的时候form表单中的select等不能渲染的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
var getXY = function() { // 判断是否是 IE if (document.documentElement.getBoundingClientRect) { // 注1 return function(el) { var box = el.getBoundingClientRect(); var rootNode = el....
django-flatpage-widget ...该设置必须是两个元素的元组,其中第一个是使用django的get_callable解析为可调用对象的get_callable ,第二个是将作为关键字参数传递给callable的字典。 这适用于标准Widget类。
el : Y.Dom.get(el); if (!el || !method) { return false; } // 确定返回的对象 var scope = (override) ? o : window; // 看起来是个 HTMLElement 或者不是 Array if (el.tagName
//mojit config (to use with ac.config.get() ) config: { foo: 'bar' }, //app level config (to use with ac.app) appConfig: { some: 'config param' }, // We need to...
1.2 如何把JavaScript添加到页面 3 外部JavaScript文件 5 1.3 第一个JavaScript程序 7 1.4 把文本写到Web页面上 9 1.5 附件外部JavaScript文件 10 1.6 追踪错误 12 1.6.1 Firefox JavaScript控制台 13 1.6.2 显示...
动态插入节点是最为简单也最为广泛的一种异步加载方式(例如yui的Get模块),然后使用动态插入节点方法加载的文件都会在加载后立即执行,javascript的执行一方面会占用浏览器js执行进程,另一方面也可能改变页面结构,...
首先每个管理员得对应一个角色,而角色可以操作多个栏目,...action=RoleTree&Rid=' + raw.ID,\n method: 'get', animate: true, checkbox: true }); $('#Rid').val(raw.ID); 用了一个dialog弹出进行实现ashx中传入一
Almost every website today uses some form of JavaScript, whether it be used within a server-side programming technology like ASP.NET or a JavaScript library like jQuery or Mootools, or YUI or ...
注:ExtAspNet基于一些开源的程序ExtJS, HtmlAgilityPack, Nii.JSON, YUICompressor。 示例: http://extasp.net/ 开源: http://extaspnet.codeplex.com/ 博客: http://sanshi.cnblogs.com/ 邮箱: sanshi.ustc@gmail...
注:ExtAspNet基于一些开源的程序ExtJS, HtmlAgilityPack, Nii.JSON, YUICompressor。 示例: http://extasp.net/ 开源: http://extaspnet.codeplex.com/ 博客: http://sanshi.cnblogs.com/ 邮箱: sanshi.ustc@gmail...
参考Layui数据表格文档可以看到三种layui表格渲染方式,项目选用第一种,采用Layui的异步数据接口方式,渲染表格并分页。 按照官方写法,会报跨域错误,尝试几次,发现需要设置... method :'get', contentType: '