ajax跨域未能获得响应

ajax跨域未能获得响应,ajax,https,http-post,web.xml,Ajax,Https,Http Post,Web.xml,我有两台服务器: 服务器1 URL:和 服务器2 URL: 在Server1JSP页面中,我尝试使用ajax向Server2发送POST请求 $.ajax({ type: "POST", url: "https://server2.AAA.com/servlet", data: 'test', success: function(data, textSuccess) { alert(data); } error: function(xhr, status, error) {

我有两台服务器: 服务器1 URL:和 服务器2 URL:

在Server1JSP页面中,我尝试使用ajax向Server2发送POST请求

$.ajax({
type: "POST",
url: "https://server2.AAA.com/servlet",
data: 'test',
success: function(data, textSuccess) {
       alert(data);
 }
 error: function(xhr, status, error) {
      alert('error');
 },
});
在服务器2中,我检查它是否已收到来自服务器1的请求,并尝试响应以下消息:

doPost(...) {
response.addHeader("Access-Control-Allow-Origin", "*");
response.getwriter().write("success");
}
但是,我发现服务器1无法从服务器2接收响应数据,它转到了错误警报。我完全不知道为什么会发生这种情况。我已经为所有来源设置了响应头,并且在我的应用程序的web.xml中设置了安全约束:

<security-constraint>      
<web-resource-collection>
  <web-resource-name>test</web-resource-name>
  <url-pattern>/*</url-pattern>
  <http-method>POST</http-method>
 </web-resource-collection>
</security-constraint>

请告诉我还缺少什么/我应该检查什么。

数据必须是ajax请求的键值paircheck数据类型和内容类型参数?它们应该与服务器匹配。抱歉,数据“test”只是一个示例,我在请求中传递了数据:“key1:value1”,我可以看到服务器2可以检索到value1。很好。问题是我无法从服务器2获得响应。我已经设置了数据类型:html,contentType:application/x-www-form-urlencoded;字符集=UTF-8,但仍然不能。