Because of security considerations, JavaScript is limited to cross-domain access, but sometimes we want to be able to do some reasonable cross-domain access things, so what to do?
There are two types of situations:
One, access to the page between subdomains based on the same parent domain
See the following 3 domain domains:
1、taobao.com
2、jipiao.taobao.com
3、promotion.taobao.com
They have the same parent domain taobao.com
Second, based on the access between different parent domain pages
See the following 3 domain domains:
1、taobao.com
2、baidu.com
3, sina.com.cn
They have different parent domains.
Scenarios for resolving cross-domain between them:
<!--[if!supportlists]-->①<!--[endif]--> Server proxy: Domain A's page JS needs access to the link under Domain B to obtain data, which establishes a proxy program on the server side of Domain A ( May be ASP, servlet, and so on any server-side program, domain A page JS directly call this domain proxy program, proxy program is responsible for the request sent to the link under the domain B and get the data, and finally through proxy to return the data to the page JS use.
After the access process is: Domain A under the Js--à domain A proxy---à domain B under the link
Example:
First step:
JavaScript script on domain a:http://jipiao.taobao.com/test.htm page
<script type=”text/javascript”>
Var sUrl=” http://Jipiao.taobao.com/proxy.do”; //本域下代理地址
var callback =
{
success: function(res) { alert(res.responseText); },
failure: function(res) { alert(‘failure’);},
argument:{}
}
YAHOO.util.Connect.asyncRequest(’GET’, sUrl, callback, null);
</script>