jQuery ajax load() show request status

Description

jQuery ajax load() show request status

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Showing Ajax Load Request Status in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#box").load("jquery-val.html", function(responseTxt, statusTxt, jqXHR){
            if(statusTxt == "success"){
                document.getElementById("demo").innerHTML = 
                   "New content loaded successfully!";
            }//from  w w  w. j  a v a2 s  .  c o  m
            if(statusTxt == "error"){
                document.getElementById("demo").innerHTML = 
                   "Error: " + jqXHR.status + " " + jqXHR.statusText;
            }
        });
    });
});
</script>
</head>
<body> 
    <p id="demo"></p>
    <div id="box">
        <h2>Click button to load new content inside DIV box</h2>
    </div>
    <button type="button">Load Content</button>
</body>
</html>



PreviousNext

Related