日期:2014-05-16  浏览次数:21362 次

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