Ajax - Send a Request to Server
Advertisements
Send a Request to Server using Ajax
XMLHttpRequest Object, following methods are allow to interact with the server.
Property | Description |
---|---|
open(method, url, boolean) | Specifies the type of method, URL and Boolean(if true than handle asynchronous or false than handle synchronous)
|
send("string") | String: use only POST method request. |
GET or POST Method
- GET is simpler and faster than POST, so mostly use a GET.
- POST request use when sending a large amount of data to the server, update contain on the server also POST is secure and robust method than GET.
- POST request use to send the data to send to the server.
GET Method
Syntax
xmlhttp.open("GET", url, true) // xmlhttp is variable name xmlhttp.send()
Example Send a Request to Server using Ajax
req.open("GET", "ajax_demo.txt", true); // req is variable name req.send(null);
Post Method
Syntax
xmlhttp.open("POST", url, true) // xmlhttp is variable name xmlhttp.send(String)
Example Send a Request to Server using Ajax
req.open("POST", "ajax_demo.txt", true); // req is variable name req.send("hitesh");
Google Advertisment