Realization of Cross-domain and Ajax cross-domain problem in JS _javascript skills

Source: Internet
Author: User
JS to cross the domain, you can use:
<script src= "Other site's JS address (here can be dynamically generated, such as: aaa.jsp, bbb.aspx) can be. "></script> is able to read data from other sites," he said.
The key is to see your spirit is not flexible, will not use.
Ajax to cross domain, you can use the server to other sites to take content, such as asp.net:
Copy Code code as follows:

public string geturldata (string url)
{
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (URL);
System.Net.WebResponse WebResponse = Webrequest.getresponse ();
System.IO.Stream IStream = WebResponse.GetResponseStream ();
System.IO.StreamReader sr = new System.IO.StreamReader (IStream, System.Text.Encoding.Default);
String str = Sr. ReadToEnd ();
Sr. Close ();
Istream.close ();
WebResponse.Close ();
return str;
}

This method has already been written, you can get the Ajax return value you want as long as you pass in the URL address of the website.
This will be another site's Ajax request, write to their own server, and then you use AJAX to request your own written the
The ASPX address is OK.
If it's Java, it's the same thing, like:
Copy Code code as follows:

URL url = new URL ("http://www.jb51.net/index.html");
FilterInputStream f= (FilterInputStream) Url.openstream ();

Of course, the principle of asp,php is the same, that is, the use of the thief function to achieve access to content.
Related Article

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.