jQuery ajax with Credentials

Posted in :

比較官方的 jQuery Ajax 與 我自己的 jQuery Ajax 的結果, 在chrome 裡都改用 fetch 的結果有微微的不同, 我的 ajax 產生的 fetch 的 Credentials 並不是 “include”, 而是 “omit”

解法:

加入 xhrFields: { withCredentials: true }, 就可以了.

$.ajax({
	url: "your-url",
	type: "POST",
	contentType: "application/json; charset=utf-8",
	cache: false,
	dataType: "json",		
	xhrFields: { withCredentials: true },	
	success: function (retval, textStatus) {
		console.log( JSON.stringify(retval));
	}
});

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *