我必须点击一个 url http://localhostName:8080/TestModule?paramA=3432¶mB=0.
我的代码不适用于具有多个参数的 URL,但它工作得很好对于单个参数,请说 'http://localhostName:8080/TestModule?paramA=3432.
有人可以告诉我为什么会发生这种情况吗?任何帮助,将不胜感激。提前致谢。
我正在使用以下启用 CORS 的调用进行 xhr 调用。
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
此外,我还在 tomcat 的 web.xml 中添加了以下过滤器,并且还在 tomcat 的 lib 中添加了所需的 cors-filter-2.1 jar 和 java-property-utils-1.7.1.jar。
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
最佳答案
这只不过是一个错误的 URL 问题,在 TestModule 之后添加/并且它开始工作了。 :) http://localhostName:8080/TestModule/?paramA=3432
关于javascript - 多参数 URL CORS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27605732/