Ajax跨域请求,无法传递及接收cookie信息解决方案 (开发背景:实现跨域登录)

//php脚本增加
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Credentials: true');
/*js设置登录状态*/
$.ajax({
    url:"https://goonls.com/sign-in.php",
    cache:false,
    data:{user:$('#user_email').val(),password:$('#exampleInputPassword1').val()},
    method:"POST",
    dataType:'json',
    xhrFields:{//这里是重点
        withCredentials:true
    },
    success:function (data) {

    },
    error:function (e) {

    }
});

参考地址

https://www.cnblogs.com/yalong/p/9067525.html

HTML5 Access-Control-Allow-Origin解决跨域问题