Section 3.3. How to Decide on a Request Type


3.3. How to Decide on a Request Type

There are two main request types used in AJAX communication: POST and GET. These are the identical choices you have with forms in HTML, and the same rules apply. GET requests can be used when the URL performs no action. (For example, a URL such as index.php?section=main that displays the main section of a Web site is a good use for GET.) A URL such as index.php?action=delete&id=1 should never be used with GET. The main reasons for this go back to the HTTP standard, which suggests that GET requests should not perform permanent actions and are not allowed to be cached by proxies and other infrastructure. Some Web accelerator products also prefetch GET URLs from pages, which causes huge problems when they hit a URL that deletes a record. GET requests also have the drawback of potentially limiting the amount of data that the client can send to the server; current HTTP specs don't limit size, but many servers and browsers limit the size to around 2,000 characters. POST requests aren't allowed to be cached by proxies or prefetched, and thus are much safer than GET requests.

In most AJAX setups, especially any using an RPC approach, only POST requests should be used. While some of the requests might be just to load new data, it's generally too hard to keep track of which type of request is which. In a document-centric approach, GET requests might be useful, especially when you're using AJAX to load in chunks of static HTML or XML content. If you go with an approach like that, you'll want to use a good naming convention to help keep track of which type of request is needed for each URL.




Understanding AJAX(c) Using JavaScript to Create Rich Internet Applications
Understanding AJAX: Using JavaScript to Create Rich Internet Applications
ISBN: 0132216353
EAN: 2147483647
Year: N/A
Pages: 154

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net