Since the day AJAX was born, the problem that XMLHttprequest objects cannot be requested across domains has always existed. This seems to be a very classic question. It is caused by the same origin policy of JavaScript (not discussed in depth here).
The solutions are probably as follows:
1. Use the middle layer transition method (can be understood as "agent"):
Intermediate transition, obviously, is to add a layer of transition in the middle of AJAX communication with servers in different domains. This layer of transition can be any language with network communication functions such as PHP, JSP, C, etc., from the middle layer to Servers in different domains perform data reading operations. Take asp.net as an example. If you need to communicate with an asp.net in different domains, the client's xmlhttprequest first queries an asp.net in this domain, and then the asp.net in this domain communicates with the asp.net in different domains. .net for communication, and then the asp.net response output (response) of this domain; the idea is probably like this, I believe readers have a clear understanding.
2. Use the <script> tag </script>
This method is to use the src in the <script> tag to query an aspx to obtain the response, because the src attribute of the <script> tag does not have cross-domain issues. </script>
Let’s give an example to make it clearer:
protected void Page_Load(object sender, EventArgs e)
Response. Write("var responseVal='Dylan'");
}
}
}
This method is also called ajaj or ajax without xmlHttprequest, replacing x with j, It's because the <script> tag is used instead of xml and xmlHttprequest. This method seems a bit "alternative", haha. <BR>
<BR>Now let’s see how to solve the cross-domain problem of ajax with jQuery: <BR></script>
Copy code