Javascript jQuery&;CORS在打开的远程服务器上总是失败

Javascript jQuery&;CORS在打开的远程服务器上总是失败,javascript,jquery,ajax,cors,Javascript,Jquery,Ajax,Cors,我试图在一个应该启用CORS的远程服务器上,使用jQuery$.ajax()方法模拟一篇文章 其想法是提交一个提供用户名/密码的表单,并从成功的身份验证中获得服务器交付的cookie 以下是jQuery: $.ajax({ type: 'POST', crossDomain: true, async: false, url: this.url, data: { username: this.username, passwor

我试图在一个应该启用CORS的远程服务器上,使用jQuery
$.ajax()
方法模拟一篇文章

其想法是提交一个提供用户名/密码的表单,并从成功的身份验证中获得服务器交付的cookie

以下是jQuery:

$.ajax({
    type: 'POST',
    crossDomain: true,
    async: false,
    url: this.url,
    data: {
        username: this.username,
        password: this.password
    },
    xhrFields: {
        withCreditentials: true
    },
    success: function(responseData, textStatus, jqXHR) {
        console.info(jqXHR.getAllResponseHeaders());
    },
    error: function(responseData, textStatus, errorThrown) {
        console.warn(errorThrown);
    }
});
以下是响应标题:

HTTP/1.1 200 OK
Connection: close
Content-Type: text/html
Pragma: no-cache
Cache-control: no-cache,max-age=0,must-revalidate
Content-Encoding: gzip
Vary: Accept-Encoding
Transfer-Encoding: chunked
和请求头:

Accept: * / *
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr,en-US;q=0.8,en;q=0.6
Cache-Control: max-age=0
Connection: keep-alive
Host: my remote server (URL is hidden)
问题是我得到了一个控制台。警告告诉我:

Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'URL'
我还尝试了一个模拟POST的Chrome扩展:我在jQuery中输入了相同的数据,从调用到表单提交后传递的cookie,一切都成功了

我不明白我的jQuery为什么无法加载URL,但却给了我一个200 OK!我不知道该怎么做才对


我哪里出错了?

似乎需要将
访问控制允许源代码:
头添加到api响应头中。您的REST客户端(chrome扩展)不遵守浏览器那样的CORS规则,这就是它工作的原因。

没有启用CORS。@MinusFour您怎么知道?我的系统管理员告诉我CORS已启用,chrome扩展succeed@PierreLeBot将有一个
Access Control Allow Origin
response header我们在
数据{username:this.username,password:this.password}
@PHPglue中看不到
this
是什么,这只会让问题变得更糟。这可能是我在下面提到的CORS问题。好的,谢谢,但我想这是服务器端的问题,对吗?好的,让我和系统管理员一起看看,我会给你回复(并验证你的答案)。这种修改应该足够了吗?我的jQuery正确吗?@PierreLeBot jQuery看起来很好。@PierreLeBot您不太可能需要设置
跨域
property@PierreLeBot详细解释菲尔说的话。。。如果您试图“在同一域上强制跨域请求(如JSONP)”,则只需设置crossDomain属性,因为在默认情况下,如果您进行跨域请求,则该属性设置为true。看见