How To Change Text Using Ajax And JQuery With Example

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

AJAX is exchanging data with a server, and updating parts of a web page - without reloading the whole page.jQuery provides several methods for AJAX functionality. So today we implement a simple jquery script with ajax

How To Change Text Using Ajax And JQuery With Example

Step 1:Create index.html to impelement below code 
 

<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

<button class="btn btn-success">Get External Content</button>


Step 2:Create demo_test.txt file and write below texts in it.
 
<h1>AJAX</h1>
<p>AJAX is not a programming language.</p>
<p>AJAX is a technique for accessing web servers from a web page.</p>
<p>AJAX stands for Asynchronous JavaScript And XML.</p>


Step 3:Now impement Jquery To extract data from demo_test.text file.
 
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#div1").load("demo_test.txt");
        });
    });
</script>



Complete Code For Changing Text Using Ajax And Jquery 
 
<!DOCTYPE html>
<html>
<head>
    <title>How To Change Text Using Ajax And 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>
    <div class="text-center">
        <h2 id="color" style="color: White;">How To Change Text Using Ajax And Jquery</h2>
    </div>
    <br>

    <div class="well">

        <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

        <button class="btn btn-success">Get External Content</button>
    </div>

</div>
</body>
</html>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#div1").load("demo_test.txt");
        });
    });
</script>

 

Related Post