Cross-domain issues between the Ajax master domain and the subdomain

Source: Internet
Author: User
Tags subdomain

In some scenarios, it is necessary to invoke an interface in the subdomain in the primary domain, and if an AJAX request is made directly to the subdomain in the primary domain, the cross-domain error is reported and the IFRAME can be used to resolve the cross-domain problem.
If the primary domain is www.baidu.com, the subdomain is baike.baidu.com. A page in the primary domain needs to call a service in the subdomain through an AJAX request. First, you need to prepare a B page in the subdomain, B is a simple empty page, it is best to bring jquery to the B page, so that you can directly use jquery to send AJAX requests, in the main domain A page with an IFRAME to the B page URL address.

b page Format

1//b.html 2 

A page format

1//a.html 2 

One thing to note is that in a page, to wait for the IFRAME tag to finish loading b page, then take the contentdocument of the IFrame object, otherwise if the B page is not fully loaded by the IFRAME, The jquery object in page B is not taken from the Contentdocument property on page A. Once the jquery object in the B page is taken, the AJAX request can be sent directly, and this kind of "proxy" method can solve the cross-domain problem of the master domain.

Cross-domain issues between the Ajax primary domain and the subdomain

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.