Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of cookie loss of ajax cross-domain request data

Shulou Source: shulou.com Published: 2022-06-03 09:21:17 11月15日 Update

This article introduces the knowledge about "how to solve the problem of Ajax cross-domain request data cookie loss". In the actual case operation process, many people will encounter such a dilemma. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Front end:

Take jquery for example:

need to join

The copy code is as follows:

xhrFields: {

withCredentials: true

},

crossDomain: true,

$.ajax({

type: postType,

url: url,

data: postData || '',

xhrFields: {

withCredentials: true

},

crossDomain: true,

success: function () {

successCallback.apply(scope || this, arguments);

},

failureCallback: function () {

failureCallback.apply(scope || this, arguments);

},

dataType: dataType

});

Server side:

Take PHP for example:

The copy code is as follows:

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

header('Access-Control-Allow-Origin: http://m.z.com');

Depending on your situation.

"How to solve the problem of Ajax cross-domain request data cookie loss" is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Code data problems content situation more knowledge practicality learning next front end dilemma reality articles servers cases editing websites industries processes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information Microsoft NVidia Xiaomi