使用服务器端设置跨域响应头,确保请求凭据发送到目标服务器。
示例代码:
服务器端代码(PHP): header('Access-Control-Allow-Origin: http://localhost:8080'); header('Access-Control-Allow-Credentials: true');
Ajax请求: $.ajax({ url: 'http://example.com/api/data', xhrFields: { withCredentials: true } });
上一篇:Ajax授权后,购物车将被清空。