Ajax cross-domain request cannot carry cookie problem

Source: Internet
Author: User
Tags http authentication
Client Settings 1. Native JS setting mode:
true; '

2.jQuery or Zepto setting mode:

$.ajax ({  ...  Xhrfields: {     true  },  ...})

By default, cross-origin requests do not provide credentials (cookies, HTTP authentication, and client SSL certificates, etc.). By setting the Withcredentials property to True, you can specify that a request should send credentials. This allows the cross-domain cookie to be shared, such as your two-level domain to get a cookie for your first-level domain name or vice versa. Service-Side settings The following is the settings for the PHP version:

Header ("Access-control-allow-credentials:true");

If a request with a credential is sent, but the server does not contain the header, the browser does not give the corresponding data to JavaScript. As a result, the responsetext will be an empty string, the status value is 0, and the OnError () event handler will be called.

Ajax cross-domain request cannot carry cookie problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.