Javascript AJAX请求在Firefox中失败,在IE中工作(两种情况下服务器都返回200)

Javascript AJAX请求在Firefox中失败,在IE中工作(两种情况下服务器都返回200),javascript,ajax,Javascript,Ajax,我正在本地测试。我让IIS在localhost:50972上提供JS和HTML,在localhost:8080上作为应用服务器使用Java/Jersey 以下AJAX请求在Internet Explorer中成功,但在Chrome和Firefox中失败,即使服务器显示200 OK: public getTest() { var settings: JQueryAjaxSettings = { url: "http://localhost:8080/getData",

我正在本地测试。我让IIS在localhost:50972上提供JS和HTML,在localhost:8080上作为应用服务器使用Java/Jersey

以下AJAX请求在Internet Explorer中成功,但在Chrome和Firefox中失败,即使服务器显示200 OK:

public getTest() {
    var settings: JQueryAjaxSettings = {
        url: "http://localhost:8080/getData",
        type: "GET",
        crossDomain: true,
        dataType: "text",
    };

    jQuery.ajax(settings).done(function (o) {
        alert(o);
    }).fail(function (request) {
        alert(request);
    });
}
Java端的代码如下所示:

@GET
@Path("/getData")
public Response getData() {

    NewCookie cookie = new NewCookie("test", "key:val", "/", null, "comment", 100, false );
    return Response.status(Response.Status.OK).entity("Hello World").cookie(cookie).build();
}
以下是IE和Firefox的相关HTTP请求/响应:

Internet Explorer请求(成功)

Firefox请求(失败)

来自服务器的响应(发送到两者)


我也尝试过用
{}
dataType:json
代替
helloworld
dataType:text
,但没有改变。我也曾尝试过<代码>交叉域:Trime< /Cord>和交叉域:false < /Cord>帮助>

< P>所观察到的行为是因为Firefox(和Chrome等)正确地考虑了不同的端口以建立不同的原点;我不知道

见:

如果两个页面的协议、端口(如果指定了一个)和主机相同,则两个页面具有相同的来源

..[但]IE不将端口包含在同一来源组件中,因此,和被视为来自同一来源,不受任何限制


使用-在服务器上启用-请求在所有浏览器中成功。

您在服务器上未启用CORS的情况下进行跨域请求这似乎就是问题所在。
GET http://localhost:8080/getData?_=1451863561652 HTTP/1.1
Referer: http://localhost:50972/
Accept: text/plain, */*; q=0.01
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Connection: Keep-Alive
DNT: 1
Host: localhost:8080
GET http://localhost:8080/getData?_=1451863686206 HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/plain, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:50972/
Origin: http://localhost:50972
Connection: keep-alive
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: test=key:val;Version=1;Comment=comment;Path=/
Content-Type: text/plain
Content-Length: 11
Date: Sun, 03 Jan 2016 23:26:07 GMT

Hello World