惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
B
Blog
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
D
DataBreaches.Net
B
Blog RSS Feed
小众软件
小众软件
人人都是产品经理
人人都是产品经理
I
InfoQ
P
Proofpoint News Feed
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
The GitHub Blog
The GitHub Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - sharplife

CMMI的五个台阶 记个链接,RMS & Moss 文档保护 2010, Nginx + Apache, mod_wsgi serve python web application (test with TG2) Pylons unicode document Python 2.x Unicode 简记 TurboGears 2.0 beta6 安装 严冬 感受危机 这就是生活了 汉字及英文字符的ascii表示 推荐阅读:如何读一本书 [转]做人做事~ [转]Create an XMLSerializer from a given XML string 十一结束~ 离开 css image crop tech c# 3.0 quick reference XML Entities 参考
CSSHttpRequest : cross domain ajax request for easy
sharplife · 2009-03-20 · via 博客园 - sharplife

异步http请求的跨域问题,google一下已经有好几种解决方案了,像是JSONPwindow.name等方式,没细看,感觉都挺麻烦的。

无意中看到一种借用CSSHttpRequest的方式(相对应于XmlHttpRequest),借助于web页面对css的请求无domain限制的原理,在server端将需要的数据编码成css方式返回给client,而client借助js来解码数据并执行相应操作,ok啦,简单、方便。http://nb.io地址可能是访问不了的,把文章贴出来(google):

nb.io

CSSHttpRequest is cross-domain AJAX using CSS.

  • Cross-browser —supports IE6+, Firefox 2+, Safari 3+, iPhone.
  • 100% JavaScript —no Flash required.
  • Small —2.4KB minified.

Like JavaScript includes, this works because CSS is not subject to the same-origin policy that affects XMLHttpRequest.  CSSHttpRequest functions similarly to JSONP , and is limited to making GET requests. Unlike JSONP, untrusted third-party JavaScript cannot execute in the context of the calling page.

A request is invoked using the CSSHttpRequest.get(url, callback) function:


     CSSHttpRequest.get(

Data is encoded on the server into URI-encoded 2KB chunks and serialized into CSS rules with a modified data: URI scheme. The selector should be in the form #c<N> , where N is an integer index in [0,]. The response is decoded and returned to the callback function as a string:


     #c0 { background: url(data:,Hello%20World!); }
     #c1 { background: url(data:,I’m%20text%20encoded%20in%20CSS!); }
     #c2 { background: url(data:,I%20like%20arts%20and%20crafts.); }

CSSHttpRequest * is open source under an Apache License (Version 2.0).

* Or as Eric refers to it, AJACSS (slightly more electro). * Or as Eric refers to it, AJACSS (slightly more electro).

Examples Examples.

源码在github上的下载地址:http://github.com/nbio/csshttprequest/tree/master, 目前有Python/Ruby/PHP的server端实现(即编码功能),抽时间可以做一下其他实现,如.NET