All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

jQuery Ajax Get and Post

With the help of jQuery Ajax Get and Post you can request data to the server without page refresh using HTTP GET or POST request.


Difference Between GET and POST request

  • GET:is used to request data from the server or any source
  • POST:is used to submit data to the server or any source

  • jQuery GET Method

    jQuery GET Method is used to get data from the server or any specified source


    Syntax

    $.get(URL,callback);


    Code Explanation

    • URL is used to set the URL from which you can get the data
    • callback is used to set the function that is executed after request success

    Example of GET Method

    $("button").click(function(){
      $.get("demo.asp",function(data,status){
        alert("Data: " + data + "\nStatus: " + status);
      });
    });
    



    jQuery POST Method

    jQuery POST Method is used to send data to the server or any specified source


    Syntax

    $.post(URL,data,callback);


    Code Explanation

    • URL is used to set the URL from which you can get the data
    • data is the data used to send to the server or the source specified in the URL parameter
    • callback is used to set the function that is executed after request success

    Example of GET Method

    $("button").click(function(){
    $.post("demo.asp",
    {
        name:"Rokit",
        city:"MBA",
        RollNo:"3435"
    },
    function(data,status){
        alert("Data: " + data + "\nStatus: " + status);
      });
    });
    
    ❮ Previous