Ajax - Send a Request to Server

Advertisements

Create Object Ajax Ajax Response

Send a Request to Server using Ajax

XMLHttpRequest Object, following methods are allow to interact with the server.

PropertyDescription
open(method, url, boolean)Specifies the type of method, URL and Boolean(if true than handle asynchronous or false than handle synchronous)
  • method: type of request, GET or POST
  • url: the location of the file o the server (with path)
  • boolean: true (asynchronous) / false (synchronous)
  • optionally: You wish to login and password may be added to arguments
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");

Create Object Ajax Ajax Response

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet


For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements