被这个坑太多次了,55555
后台加:
header('Access-Control-Allow-Credentials: true'); header("Access-Control-Allow-Origin: *");//允许ajax跨域 header('Access-Control-Allow-Methods:GET, POST, OPTIONS');
前端ajax代码:
$.ajax({ url: "xxx", type: "POST", data: {}, dataType: "json", xhrFields: { withCredentials: true }, crossDomain: true, error: function () { }, complete: function () { }, success: function (getdata) {//如果调用php成功 } })