简体   繁体   English

使用jQuery 1.8.3和1.9.1的CORS

[英]CORS using jQuery 1.8.3 vs 1.9.1

I am trying to make a PATCH/POST using CORS. 我正在尝试使用CORS进行PATCH / POST。 The code below works on jQuery 1.9.1 but not works on 1.8.3. 以下代码在jQuery 1.9.1上有效,但在1.8.3上无效。

var settingsB = {
          "async": false,
          "crossDomain": true,
          "url": "https://wmmr85ap13.execute-api.us-west-2.amazonaws.com/dev/customer/" + m,
          "method": "PATCH",
          "headers": {
            "content-type": "application/json"
          },
          "data": JSON.stringify({isFirstLogin: "false"})
        }

        $.ajax(settingsB).done(function (response) {

            console.log(response);
        });

On the jquery 1.8.1 I am getting: 在jQuery 1.8.1上,我得到:

XMLHttpRequest cannot load https://wmmr85ap13.execute-api.us-west-2.amazonaws.com/dev/customer/jvthales@gmail.com ?{%27isFirstLogin%27:%20false%20}. XMLHttpRequest无法加载https://wmmr85ap13.execute-api.us-west-2.amazonaws.com/dev/customer/jvthales@gmail.com?{%27isFirstLogin%27:%20false%20 }。 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. 对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。 Origin ' http://emporiodacerveja.vtexcommercestable.com.br ' is therefore not allowed access. 因此,不允许访问来源' http://emporiodacerveja.vtexcommercestable.com.br '。 The response had HTTP status code 400. 响应的HTTP状态码为400。

I imagine that the CORS is well configured on the server because the jQuery 1.9.1 works! 我猜想由于jQuery 1.9.1可以在服务器上正确配置CORS!

Is there any diffence doing post/patch using 1.9.1 vs 1.8.3 version? 使用1.9.1和1.8.3版本进行发布/修补时有什么区别吗?

EDITED: See below the difference between 1.9.1 vs 1.8.3 calls: 编辑:请参见下面的1.9.1与1.8.3调用之间的区别:

jQuery 1.8.3

jQuery 1.9.1

Need to set type and xhrFields 需要设置类型和xhrFields

$.ajax({
   type : "PATCH",  //replaced my method in 1.9
   url: cross_domain_url,
   xhrFields: {
      withCredentials: true
   }
});

The method parameter was added in jQuery 1.9.0. method参数是在jQuery 1.9.0中添加的。

method 方法
(default: 'GET') (默认:“ GET”)
Type: String The HTTP method to use for the request (eg "POST", "GET", "PUT"). 类型:字符串用于请求的HTTP方法(例如“ POST”,“ GET”,“ PUT”)。 (version added: 1.9.0) (添加的版本:1.9.0)

source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM