XMLHttpRequest

Next ❯Ajax Request

It's an object which is supported by all modern browsers now a days to run AJAX

Syntax - To declare XMLHttpRequest object
new XMLHttpRequest();
Example:
var xhr = new XMLHttpRequest();
  • XMLHttpRequest object must be declared to perform background operation(s)


XMLHttpRequest object contains predefined methods & properties to perform communication with server in background

  • turned_in_notMethods
    MethodsDescription
    abort()To cancel the current request
    open(method,url,async,user,pwd)Request settings,
    method: Request type (like: GET, POST, HEAD)
    url: URL Path
    async: Asynchronous true/false
    user: username for url authentication (if any)
    pwd: password for url authentication (if any)
    send()Request the server using GET method
    send(data)Request the server using POST method
    setRequestHeader(header,value) To send any header to the server
    getResponseHeader(headerName) Returns specific response header value
    getAllResponseHeaders() Returns all response header values

  • turned_in_notProperties
    PropertiesDescription
    onreadystatechangeDefines a function, called if readyState property changes
    readyStateHolds the status-code of the XMLHttpRequest
    0: request not initialized
    1: server connection established
    2: request received
    3: processing request
    4: request finished and response is ready
    statusReturns the status-code of a request
    200: "OK",
    404: "Not Found",
    Many more Http Message & codes
    statusTextReturns the status-text (e.g. "OK" or "Not Found")
    responseText To access the response data as a string
    responseXML To access the XML response data
    responseURL Returns the response url

  • Ajax Request
❮ Prev Getting Started
Next ❯Ajax Request
TryOut Examples"Learn to Explore..!"

TryOut Editor

receipt