`
hqman
  • 浏览: 352691 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

解决dwr跨域问题

    博客分类:
  • ajax
阅读更多

有这样的需求 a.com 要通过 ajax 访问 b.com的数据

dwr 2.0提供了 跨域访问的功能

 

 
dwr写道
Cross Domain Ajax: <script> tag manipulation

Should you need to access servers in a different domain we've enabled a new remoting scheme. From DWR 2.0 you can use manipulation of <script> tags in addition to XMLHttpRequest or iframes. To use is you just need to do the following:
DWREngine.setMethod(DWREngine.ScriptTag);

 

 

dwr 写道
To allow cross-domain script tag requests you need to add the following incantation to web.xml:

<init-param>
<param-name>allowGetForSafariButMakeForgeryEasier</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>allowScriptTagRemoting</param-name>
<param-value>true</param-value>
</init-param>

To configure the client where to send cross-domain requests, set the ._path variable for the remote interface in question:

Remote._path = 'http://otherdomain.com/webapp/dwr';
Remote.someFunction();

Cross-domain remoting may not work properly with reverse ajax.
 

实际开发

 

js 写道
<script type='text/javascript' src='http://a.com/dwr/interface/regutil.js'></script>
<script type='text/javascript' src='http://a.com/dwr/engine.js'></script>

<script type='text/javascript' src='http://a.com/dwr/util.js'></script>

 

  

js 写道
DWREngine.setMethod(DWREngine.ScriptTag);
regutil._path = 'http://sso.dxy.cn/dwr/';
 

 

   

调用方法 出现  XMLHttpRequest.open 时权限不足

 

网上搜索了下 很多人说是 firefox的bug

 

再次搜索  看到scripttag 能搞定此问题

 

把js  的引入 改成 动态 加载 果然可以了 哈哈 biggrin

 

注意点:dwr jar需要是2.0.2

 

 

 

分享到:
评论
3 楼 fzfx88 2011-05-27  
貌似Apache + tomcate 可以解决
2 楼 rootzwy 2008-09-16  
请问一下,你跨域同步问题是怎么解决的?我用dwr.engine.setAsync(false);怎么没有起作用?
1 楼 oohehe1029 2008-08-21  
    我也在为dwr跨域问题郁闷呢。想请教一下,你的js动态加载是用哪种方法实现的。能加个QQ让我详细请教一下吗?谢了大侠!Q:37422667

相关推荐

Global site tag (gtag.js) - Google Analytics