How to Create AJAX Loading Method using JQuery

How to Create AJAX Loading Method using JQuery

In this article, you will learn How to Create AJAX Loading Method using JQuery.

Example:-

<html>
<head>
<title>AJAX Load Method in JQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").load("test.txt", function(responseTxt, statusTxt, xhr){
      if(statusTxt == "success")
        alert("External content loaded successfully!");
      if(statusTxt == "error")
        alert("Error: " + xhr.status + ": " + xhr.statusText);
    });
  });
});
</script>
</head>
<body>
<div id="div1"><h2>AJAX Load Method in JQuery</h2></div>
<button>Get External Content Now</button>
</body>
</html>

test.txt

This is External test file content will be display after a click on “Get External Content” Now Button

Read on Facebook

Leave A Reply