jQuery ajax() Handle error in ajax

Description

jQuery ajax() Handle error in ajax

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from   w ww . j a va  2 s  .c om
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.ajax({url: "wrongfile.txt", error: function(xhr){
      document.getElementById("demo").innerHTML = 
            "An error occured: " + 
            xhr.status + " " + 
            xhr.statusText;
    }});
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<div></div>

<button>Get</button>

</body>
</html>



PreviousNext

Related