Ajax is Asynchronous JavaScript and XML. By performing a small amount of data exchange with the server in the background, AJAX can implement asynchronous updates on webpages. This means that you can update a part of a webpage without reloading the entire webpage.
Interaction Process:
1 -- start to get the XMLHTTPRequest object
2 -- open the URL channel and set asynchronous transmission
3 -- send sends data to the server
4 -- the server receives and processes the data, and returns the result after the processing is complete.
5 -- the client receives the response from the server
Synchronous and asynchronous
Synchronization: the script will stay and wait for the server to send a response and then continue
Asynchronous: the script allows the page to continue its process and process possible replies.
Cross-origin Ajax problems:
If we want to use ajax to obtain specific content in website B on website a, if website A is not in the same domain as website B, cross-origin access may occur.
For cross-origin access, IE prompts a warning box to remind you. If a user adds the website to a trusted website or lowers the security level, ie will not remind you of this issue.
If Firefox or other non-Microsoft browsers encounter cross-origin access, the solution is to reject access.
Several feasible solutions:
1. Web proxy method. That is, the cross-origin access requests to website B generated when you access website a are submitted to the specified page of website a. The page replaces the user page to complete interaction and return appropriate results. This solution can solve most of the Cross-origin access problems that can be considered at this stage, but requires website A to provide support for Web Proxy. Therefore, website a and website B must work closely together, in each interaction process, the server load of website a increases and the session status cannot be saved on behalf of users.
2. On-demand mode. Mymsn portal uses this method, but mymsn does not involve cross-origin access. Dynamically control the generation of SCRIPT tags. You can call cross-origin pages by modifying the src attribute of SCRIPT tags. This solution has the defect that the get method is adopted when the src attribute of the script completes the call. If the string passed during the request is too large, it may fail to run normally. However, this solution is very suitable for aggregation portals.
3. IFRAME mode. After checking a post about cross-origin access on javaeye, he mentioned that he has used IFRAME to solve cross-origin access problems. The IFRAME method can be used to submit and obtain data. However, because the parent window cannot interact with the Child Window (in the case of cross-origin access, this interaction is denied ), therefore, the effect on the parent window cannot be completed.
4. Local User dump mode: the feature that IE is attached to the Windows platform provides us with an IFRAME-based "Bypass" solution using memory, that is, data can be transmitted between two windows Windows through the windows clipboard on the client. You only need to set interval on the receiving side for polling. After obtaining the result, you can clear interval. The platform independence of FF determines that it does not support the clipboard method. In the previous versions of FF, the plug-in vulnerability has been fixed, so FF cannot complete the dark Data Warehouse through memory. Because the file operation FF does not provide support (data transmission cannot be completed through cookie cross-origin), this technical method can only be used in IE.
5. In combination with the preceding methods, when accessing website a, request website B to complete data processing and obtain the desired results based on the returned ID. The disadvantage of this method is also obvious, and the load of website B is increased. The session is also maintained, and the interaction between website a and website B is enhanced. Most importantly, this solution satisfies all my needs.
To sum up, I recommend the on-demand method when you can select the above scheme. This method can solve most of your problems without submitting a large amount of data.
What Is Ajax? Ajax interaction model (process )? What is the difference between synchronous and asynchronous? What is the cross-origin Ajax solution?