网络编程
位置:首页>> 网络编程>> JavaScript>> 利用GAE&Google Gears做了一个简单的AJAX代理

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

作者:Fdream 来源:Fdream博客 发布时间:2009-04-29 12:42:00 

标签:Google,Gears,gae,ajax

Google Chrome,又喜欢逛豆瓣,Google Chrome支持User Scripts了,但是我写的那几个插件在Chrome下又跑不了。因为Google Chrome有Google 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吧,这个运用得还是非常广泛的。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com