Difference between revisions of "BTC640/ProcessingAjax"
(Created page with '= Lecture = Ajax is simply a way to make asynchronous (non-blocking) requests over the internet. Normally to make a request to a server you need to "go" to a URL, perhaps with s…') |
|||
Line 22: | Line 22: | ||
## When the response is received from the server the callback function is called automatically. | ## When the response is received from the server the callback function is called automatically. | ||
## The callback function modifies a part of the page dynamically using DOM access methods. | ## The callback function modifies a part of the page dynamically using DOM access methods. | ||
+ | |||
+ | == Ajax disadvantages == | ||
+ | |||
+ | One thing you cannot do with a page partially requested through Ajax is bookmark it. Some website designers go overboard with Ajax and make very link/button action an Ajax request. The result is that only the start page can be bookmarked. This is similar to all-flash webpages. | ||
+ | |||
+ | Also you cannot open an Ajax link in a new window or tab. This can seriously piss of your power users who do a lot on your website and need to manage their multitasking. | ||
+ | |||
+ | Also back and forward buttons don't work with Ajax requests. Again this can confuse and annoy your users. |
Revision as of 13:28, 28 March 2012
Lecture
Ajax is simply a way to make asynchronous (non-blocking) requests over the internet. Normally to make a request to a server you need to "go" to a URL, perhaps with some parameters. This is the traditional flow:
- The user clicks on a button or a link.
- The browser creates a URL for that action and queries the server for it.
- The server sends back a new page.
- The browser leaves the old page and displays the new page.
All web applications were built on this model originally. The problem is that reloading the page is expensive (both in bandwidth and time) and depending on what you're trying to do the user experience can be unacceptable. Just try to imagine Google Maps if you had to reload the page for every pan or zoom request.
Two sort-of-solutions for this problem before Ajax were frames and later iframes. Frames amost everybody hated (for various reasons). Iframes are better in many ways but they have some problems: a reload of the iframe is required to change its content, and the iframe itself has a fixed size.
Modern websites just use Ajax to create dynamic pages. An example of a flow with Ajax is:
- The user clicks on a button or a link.
- The request is handled 100% in JavaScript code, where:
- An XMLHttpRequest object is created
- A callback function is associated with that object
- A URL is created for the request (same as in the traditional flow but you have to do it yourself)
- The request for that page is sent to the server asynchronously (in the background), the user cannot see anything happening at this point.
- When the response is received from the server the callback function is called automatically.
- The callback function modifies a part of the page dynamically using DOM access methods.
Ajax disadvantages
One thing you cannot do with a page partially requested through Ajax is bookmark it. Some website designers go overboard with Ajax and make very link/button action an Ajax request. The result is that only the start page can be bookmarked. This is similar to all-flash webpages.
Also you cannot open an Ajax link in a new window or tab. This can seriously piss of your power users who do a lot on your website and need to manage their multitasking.
Also back and forward buttons don't work with Ajax requests. Again this can confuse and annoy your users.