HTML Example

Syntax

open() and send() Methods

Method

GET is far simpler and faster when compared to POST. In most cases, GET will be sufficient. POST should be used in situations such as:

You want to avoid cached filesYou need to send large amounts of data to the web serverYou need additional security over GET

If you are using GET and want to avoid cached results, append a querystring parameter that is unique to ensure that the client browser avoids cached results. This is important if your back-end data is dynamic. You want to make sure that dynamic data is being presented to the user. As you can see, you can use the GET method to send parameters via a querystring. You can also use the POST method to send form data without the use of a querystring. Here are two examples; using POST and POST sending form data.

URL

Within the open() method, the URL parameter is used to specify the address to a file on a web server. You can specify different types of files such as .txt, .asp, .aspx, .php, and .xml.

Async

Sending asynchronous requests is a huge improvement for web applications. Before Ajax, each request would require a page reload to display new data to the user. With Ajax, JavaScript can send a request to the server and continue to execute other scripts. As soon as the response is received from the server, the JavaScript code would work with the response data. This is much more efficient when dealing with multiple scripts within a document. The default setting for async is TRUE. However, if you require that the JavaScript code execute synchronously, then set this property to FALSE.

Example