我正在尝试使用位于Apache Server的ReactJS页面中的ajax调用tomcat服务器中的spring mvc应用程序中的控制器方法。在tomcat控制台中,我可以看到spring正在接收调用并处理它。然而,即使spring应用程序已经成功地处理了调用,ajax调用也不会调用“成功”函数。我的ReactJS ajax代码中还需要其他配置吗?
componentDidMount: function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/SpringApp/ajaxCallTest",
data: {testId:'345'},
dataType: 'json',
success: function(response) {
alert('in success');
}
});
}发布于 2015-05-05 22:43:14
将此代码添加到web.xml中:
<filter>
<!-- The CORS filter with parameters -->
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<!-- Note: All parameters are options, if omitted the CORS
Filter will fall back to the respective default values.
-->
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowSubdomains</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, HEAD, POST, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>X-Test-1, X-Test-2</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>3600</param-value>
</init-param>
</filter>https://stackoverflow.com/questions/30037218
复制相似问题