What is Ajax? The interaction Model (flow) of Ajax? What is the difference between synchronous and asynchronous? Ajax cross-domain solution?

Source: Internet
Author: User
Tags script tag

Ajax is asynchronous JavaScript and XML. AJAX enables Web pages to be updated asynchronously by exchanging small amounts of data in the background with the server. This means that you can update a part of a webpage without reloading the entire page.

Interactive process:

The start gets XMLHttpRequest object
2--open Open the URL channel and set the asynchronous transfer
3--send sending data to the server
4--server accepts data and processes, returns results when processing is complete
5--client receives server-side return

Synchronous and asynchronous

Synchronization: The script will stay and wait for the server to send a reply before continuing

Async: Script allows a page to continue its process and handle possible replies

Ajax cross-domain issues:  

If in a site, we want to use Ajax to get specific content in the B site, if a site and B site is not in the same domain, then there is a cross-domain access problem.

ie, for cross-domain access processing, pops up a warning box to alert the user. If a user includes the site in a trusted site, or if the security level is lowered, then IE won't remind you of it.

Other non-Microsoft browsers, such as Firefox, are experiencing cross-domain access, and the solution unification is denial of access.

A few possible scenarios:

1, the way of Web Proxy. That is, when a user accesses a site, cross-domain access requests to the B site are submitted to the specified page of site A, which is used instead of the user page to complete the interaction, thus returning the appropriate results. This scheme can solve most of the cross-domain access problems can be thought of at this stage, but requires a website to provide Web proxy support, so a site and B site must be closely coordinated, and each interaction process, a Web site server burden increased, and unable to save the session status on behalf of users.

2, On-demand way. myMSN's portal is used in this way, but cross-domain access issues are not involved in MYMSN. Dynamically controls the generation of the script tag and completes the call to cross-domain pages by modifying the SRC attribute of the script tag. The flaw with this scenario is that the SRC attribute of the script takes a way when the call is made, and if the string passed at the time of the request is too large, it may not work correctly. However, this scenario is ideal for use by the aggregation class portal.

3, IFRAME mode. Check out a post on the Javaeye about cross-domain access, and he mentions that he has solved cross-domain access issues in the form of an IFRAME. Data submission and acquisition, the use of an IFRAME is indeed possible, but the effect on the parent window effect cannot be completed because the parent window cannot interact with the child window (this interaction is denied in the case of cross-domain access).

4, the user local dump mode: IE itself attached to the Windows platform features to provide us with an IFRAME based on the use of memory to "bypass" the scheme, that is, the two window can be in the client through the Windows Clipboard data transmission, You only need to set interval on the party that accepts the data to poll, and then clear interval when you get the results. The platform independence of FF determines the way it does not support the Clipboard, and the plug-in vulnerability that existed in previous versions of FF was fixed, so FF could not complete the sneak through memory. And because the file operation FF does not provide support (it is not possible to complete data transfer across domains via cookies), this technique can only be used in IE.

5, combined with the previous several ways, when visiting a site, the first request B website to complete data processing, and then according to the return of the logo to obtain the desired results. The disadvantage of this method is also obvious, the load of the B site is increased. Advantages, the session is also implemented to maintain, while the A site and the B site between the interactive ability enhanced. The most important point is that this solution satisfies all of my needs.

To summarize, the above scenario can be selected in the case, I most recommend the On-demand way, without the need to submit a large amount of data, this way can solve most of your problems.

What is Ajax? The interaction Model (flow) of Ajax? What is the difference between synchronous and asynchronous? Ajax cross-domain solution?

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.