相关疑难解决方法(0)

跨域POST请求不发送cookie Ajax Jquery

似乎已经在stackoverflow上讨论了类似的东西,但我找不到完全相同的东西.

我正在尝试使用CORS(跨源资源共享)发送Cookie,但它无法正常工作.

这是我的代码.

$.ajax(
    { 
      type: "POST",
      url: "http://example.com/api/getlist.json",
      dataType: 'json',
      xhrFields: {
           withCredentials: true
      },
      crossDomain: true,
      beforeSend: function(xhr) {
            xhr.setRequestHeader("Cookie", "session=xxxyyyzzz");
      },
      success: function(){
           alert('success');
      },
      error: function (xhr) {
             alert(xhr.responseText);
      }
    }
);
Run Code Online (Sandbox Code Playgroud)

我没有在请求HEADER中看到这个cookie.

javascript cookies ajax jquery cross-domain

59
推荐指数
4
解决办法
9万
查看次数

标签 统计

ajax ×1

cookies ×1

cross-domain ×1

javascript ×1

jquery ×1