技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 服務(wù)器類 >

Ajax跨域請求COOKIE無法帶上的完美怎么解決

來源:技術(shù)員聯(lián)盟┆發(fā)布時間:2017-05-28 12:46┆點(diǎn)擊:

  1、原生ajax請求方式:

  1 var xhr = new XMLHttpRequest();

  2 xhr.open("POST", "", true);

  3 xhr.withCredentials = true; //支持跨域發(fā)送cookies

  4 xhr.send();

  2、jquery的ajax的post方法請求:

  $.ajax({

  type: "POST",

  url: "",

  dataType: 'json',

  // 允許攜帶證書

  xhrFields: {

  withCredentials: true

  },

  // 允許跨域

  crossDomain: true,

  success:function(){

  },

  error:function(){

  }

  })

  3、服務(wù)器端設(shè)置:

  header("Access-Control-Allow-Credentials: true");

  header("Access-Control-Allow-Origin: ");