Home > Web Front-end > JS Tutorial > body text

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

亚连
Release: 2018-05-25 11:54:40
Original
1659 people have browsed it

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
    });
Copy after login

Server side:

Take php as an example:

header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Origin: http://m.z.com');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!