Home > Article > Web Front-end > Solve the problem of Ajax cross-domain request data cookie loss
This article mainly uses front-end jquery and server-side php as examples to solve the problem of ajax cross-domain request data cookie loss. It is recommended to friends who have the same needs.
Front end:
Take jquery as an example:
Need to join
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 as an example:
header("Access-Control-Allow-Credentials: true"); header('Access-Control-Allow-Origin: http://m.z.com');
It depends on your own situation
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Using ajax to change page content and address bar URL without refreshing
AJAX processing method for XML returned by the server
The above is the detailed content of Solve the problem of Ajax cross-domain request data cookie loss. For more information, please follow other related articles on the PHP Chinese website!