jQuery ajaxSetup() handle error

Description

jQuery ajaxSetup() handle error

View in separate window

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

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

<div></div>

<button>Get</button>

</body>
</html>



PreviousNext

Related