How To Use AJAX Get Method In JQuery With Examples

admin_img Posted By Bajarangi soft , Posted On 16-10-2020

In JQuery The $ get() method requests data from the server with an HTTP GET request. So today we discuss in this article about get method

How To Use AJAX Get Method In JQuery With Examples

Syntax:

$.get(URL,callback);

The required URL parameter specifies the URL you wish to request.

The optional callback parameter is the name of a function to be executed if the request succeeds.

The following example uses the $.get() method to retrieve data from a file on the server:

Example(1)

Step 1:Create index.html to impelement below code.
 

<button class="btn btn-success">Send an HTTP GET request to a page and get the result back</button>


Step 2:Create demo_ajax.asp file and write below texts in it.
 

<%
response.write(" Hi ....Am Form External asp File ")
%>


Step 3:Now impement Jquery To extract data from demo_ajax.asp file.

 
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $.get("demo_ajax.asp", function(data, status){
                alert("Data: " + data + "\nStatus: " + status);
            });
        });
    });
</script>


Complete Code For Using AJAX Get Method In Jquery

 
<!DOCTYPE html>
<html>
<head>
    <title>How To Use AJAX Load Method In Jquery With Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<style>
    body {
        background: black;
    }
</style>
<body>
<div class="container">
    <br><br><br><br>
    <div class="text-center">
        <h2 id="color" style="color: White;">AJAX Load Method In Jquery </h2>
    </div>
    <br>

    <div class="well">
        <button class="btn btn-success">Send an HTTP GET request to a page and get the result back</button>
    </div>

</div>
</body>
</html>

<script>
    $(document).ready(function(){
        $("button").click(function(){
            $.get("demo_ajax.asp", function(data, status){
                alert("Data: " + data + "\nStatus: " + status);
            });
        });
    });
</script>

Related Post