前端ajax请求:

$.ajax({
        type: "POST",
        url: url,
        data: {'ids': id},
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        success: function(obj) {
        },
        error: function(obj) {
        }
    });

php后端设置:

 header("Access-Control-Allow-Origin: {$host}");//当前的主机例如:http://cs.com
 header("Access-Control-Allow-Methods: GET,POST,PUT,DELETE");
 header("Access-Control-Max-Age: 3628800");
 header("Access-Control-Allow-Credentials: true");

Last modification:August 20, 2020
如果觉得我的文章对你有用,请随意赞赏