How to solve the problem of cookie loss of ajax cross-domain request data
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!