What are the best methods for cross-origin Ajax problems?

Source: Internet
Author: User

When the two domains are not the same, I checked some methods on the Internet, but I still felt that it was not very good. I did not come up with a good solution to this problem!

There are roughly three methods on the Internet:

1. the most humane approach-Manual settingIn the browser settings, select "tick" for cross-origin ". A few people can use it. Too many are not feasible at all!Pass!

2. create a proxy on the server of the same domain. The browser sends a request to the proxy URL. Then, the proxy sends a request to the URL of another domain. After obtaining a response, for processing or sending them back to the browser as they are.

I don't know how it works, but intuition tells me a lot of problems, such as security and speed. In the final analysis, we still need to rely on the server. If there is a problem with the server, it will be useless!

Pass or (considerations)

3. Use the on-demand Javascript script. Generate a new <SCRIPT> dynamically on the page and direct its src attribute to the website of another website. The content returned by this website must be a legal Javascript script, which is commonly used for JSON messages.

I tried this method, but it still doesn't work. If someone else sets something for the server in another domain, it doesn't work!Pass!

 

Therefore, I have to ask you how to solve cross-origin problems? It is best not to write a proxy (I personally think there are many restrictions on the server and there are many security risks !), Is there a way to directly useCodeYou can solve this problem!

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.