Fdream's Blog
专注于WEB前端开发
Powered by Google

利用GAE&Google Gears做了一个简单的AJAX代理

27 晴天 2009-4
Fdream 发表于 Ajax Web, 已被阅读 962 次, 评论 0 条
关键词:ajax google
[ 阅读字体大小: ]

做这个的起因很简单:我喜欢用Google Chrome,又喜欢逛豆瓣Google Chrome支持User Scripts了,但是我写的那几个插件在Chrome下又跑不了。因为Google ChromeGoogle Gears,据说可以跨域Ajax,于是弄吧!结果越弄越复杂,因为Google Gears的跨域也是有很多限制的,看来还得服务器跑,还好有Google的App Engine,继续弄下去吧!

当然了,现在这个仅仅只是为Google Gears服务,写的很简单,不过还是比较“Ajax”的,看看简单的示例代码:

参考代码: [复制代码] [保存代码]

<script type="text/javascript" src="gears_init.js"></script>
<script type="text/javascript">
    var options = {
        'url': 'http://1986.appspot.com/', //你要请求的地址
        'method': 'GET'
    };
    
    var workerPool = google.gears.factory.create('beta.workerpool');

    workerPool.onmessage = function(a, b, message) {
        //alert('received: ' + message.body);
        document.write(message.body);
    };

    var childWorkerId = workerPool.createWorkerFromUrl('http://ajaxproxy.appspot.com/gears/gears_proxy.js');
    workerPool.sendMessage(options, childWorkerId);
</script>

后续的计划,起码也要实现JSONP吧,这个运用得还是非常广泛的。

Related articles 您可能对这些文章也感兴趣:
Related comments 与该文相关的评论:(我也想说几句)
Add a comment 我来说两句: 
禁止表情
禁止UBB
禁止图片
识别链接
识别关键字
表  情
arrow
用户名:   密码:  (匿名可不写) 同时注册?
验证码:   看不清?换个图片  看不清楚?换个图片

 
Copyright © 2005-2008,Fdream All Rights Reserved
Processed in 0.1406268 second(s) , unknow queries
Powered by OWord V0.1, Even Not Alpha
(此博客程序为半成品,请勿索取,以免给您的心灵造成创伤^_^)
鄂ICP备05026031号