Ajax Request

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

     
    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

     
    req.open("POST", "ajax_demo.txt", true); // req is variable name
    req.send("hitesh");