Check status and show error message for load method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:load

Description

Check status and show error message for load method

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("div").load("wrong.xml",function(response, status, xhr){
            if (status == "success"){
                //would not arrive here
            } else {/*ww  w.  j a v a2  s  . c  o m*/
                $("div").html("An error occured: <br>" + xhr.status + " " + xhr.statusText)
            }
        });
    });
});
</script>
</head>
<body>

<div></div>

<button>Test</button>

</body>
</html>

Related Tutorials