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