Ajax cross-origin requests

Source: Internet
Author: User

A part of a URL that probably contains: Scheme://host:port/path? #hash

For example, a URL of http://www.xxx.com:8888/school/student.html,

So HTTP is scheme,www.xxx.com or host,8888 is port,

What is homologous?

If the "scheme://host:port" content of the two URLs is the same, it is called homology.

What is cross-origin access?

If the scheme, host, and Port of the two URLs are not the same, they are different sources.

At this point, a URL script fetches data from another URL and is called cross-origin access.

For the Inter-hospital visit, the Web proposed a scheme called CORS (cross-origin Resource sharing), however, only modern browsers support this scenario.

How CORS works:

1) When a script from the current page in the browser requests data from another server, the browser appends an Origin header to the data header that originated the connection,

Indicates the source of the current page and then initiates a connection to another server

2) After the target server receives a connection request from the browser, if the request is accepted, add a in the header of the response data stream

The Access-control-allow-origin header, and assigns a value to the header, which is the value of the Origin header sent by the browser.

or "*" (indicates that this server is running any cross-site requests). If the request is not accepted, the Access-control-allow-origin header is not included.

3) The browser accepts packets that are returned to parse and drops the response packet if it does not contain the Access-control-allow-origin header.

About CORS, there is a foreigner Daniel (Nicholas C zakas) blog, you can see:

https://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/

for web front-end developers, there is no need to do anything, directly in Ajax to initiate cross-domain access is just a browser to do something, and then the server to support.

Ajax cross-origin requests

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.