How to solve cross-origin problems in Ajax

Source: Internet
Author: User
With the help of Goole, more and more websites are using Ajax. Program There will be many problems, mainly including the following aspects:
    • Cross-browser Problems
    • Historical backend status problems
    • Cross-origin problems

Cross-browser problems are solved because there are a lot of open-source frameworks, so we don't need to worry about it.
We can use an array to save historical records, and then save the data into historical objects. In addition, there are a lot of open-source frameworks for support, this is not a big problem.
The cross-origin problem is not a good solution, but there are still some solutions. Here are some basic solutions for you to choose from:

    1. With proxy, you can use web programs to write proxies and forward all Ajax request data. web programs can enable PHP, JSP, ASP, and otherProgramming Language. I believe you will be familiar with this method. I will not detail it here.
    2. IFRAME is used to refresh the leaf surface in a regular manner. This method only obtains data for display and cannot truly interact with the obtained data. It is not desirable to convert the dynamic data on the cost page, there are not many applications, and I will ignore them.
    3. The Apache proxy function is mainly used for Apache proxy, or for URL redirection. You can also directly link other sites to your website, in this way, you may have questions about AIA. I have introduced more than nine topics. If you are interested, you can use the following methods on your own.
    4. Using the script label, you can use real Ajax for cross-origin, and use the returned data, swear that it is very simple, the results processed by our background program are directly returned in Javascript. In our HTML, we can directly use the variables that return data to provide a simple example.

We use HTML foliar1 <! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en" >
2   < Html >
3 < Head >
4 < Title > New Document </ Title >
5 < Meta Name = "Generator" Content = "Editplus" >
6 < Meta Name = "Author" Content = "" >
7 < Meta Name = "Keywords" Content = "" >
8 < Meta Name = "Description" Content = "" >
9 </ Head >
10 < Script Language = "JavaScript" SRC = "" ID = "Get" >
11 </ Script >
12 < Script Language = "JavaScript" >
13 <! --
14 Function Get (URL)
15 {
16 VaR OBJ = Document. getelementbyid ( " Get " );
17 OBJ. SRC = URL;
18 (Obj. readstatus =   200 )
19 {
20 Alert (XML );
21 }
22 }
23 Function Text ()
24 {
25 Get (get. php );
26 }
27 // -->
28 </ Script >
29   < Body >
30 < Input Type = "Button" Value = "Click me" Onclick = "Test ()" >
31   </ Body >
32 </ Html >

Background Program get. php
Eche 'var xml = "ASDF ";';
When you click the button, you will go to the server to go to The JS you need. However, after adding the button, you can use the variable XML and run it.CodeThen you will get a dialog box showing ASDF;

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.