dwr 2.0 跨域访问的功能,Access-Control-Allow-Origin

在做dwr跨域调用时出现 Access-Control-Allow-Origin错误,后来搜了下,发现要做如下配置

 

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 写道
dwr.engine.setMethod(dwr.engine.ScriptTag);
regutil._path = 'http://sso.dxy.cn/dwr/';
 

 

 

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

 

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

 

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

 

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

 

注意点:dwr jar需要是2.0.2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值