Home  >  Article  >  Web Front-end  >  Solve the problem of Ajax cross-domain request data cookie loss

Solve the problem of Ajax cross-domain request data cookie loss

亚连
亚连Original
2018-05-25 11:54:401688browse

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

JavaScript is based on Ajax to implement non-refreshing on the web page Dynamically display file content

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn