Ajax Send Request to a Server

How to Send a Request To a Server

To send a request to a server, we use the open() and send() methods of the XMLHttpRequest object:

xmlhttp.open("GET","filename.php",true);
xmlhttp.send(null);
Method Description
open( method,url,async ) Specifies the type of request, the URL, and if the request should be handled asynchronously or not.

method : the type of request: GET or POST
url : the location of the file on the server
async : true (asynchronous) or false (synchronous)
send( string ) Sends the request off to the server.
string : Only used for POST requests

GET or POST?

POST is simpler and slower than GET, but Get is ideal for ajax and can be used in most cases.

However, always use POST requests when:

  • Sending a large amount of data to the server (POST has no size limitations)
  • Sending user input (which can contain unknown characters), POST is more secure than GET

Bookmark This Page

Link Partners