javascript - 多参数 URL CORS 错误

标签 javascript ajax tomcat xmlhttprequest cors

我必须点击一个 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/

相关文章:

javascript - Highcharts + 在图例中添加子标题/组

javascript - 避免单词 split

php - 我们如何在编写为ajax函数的php代码中显示JS警报

javascript - 异步API和回调

java - url 模式 Servlet Tomcat 7.0

javascript - 如何在 HTML 中调用 JS 函数

javascript - AngularJS 是否像 RequireJS 一样支持 AMD?

c# - AjaxUploadControl 不触发 onuploadcomplete 方法

java - 多个 WAR 文件的同一个 tomcat 单例

mysql - APIMan 与 Tomcat 和 MySQL