Set the default URL and error function for all AJAX requests: - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:ajaxSetup

Description

Set the default URL and error function for all AJAX requests:

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(){
        $.ajaxSetup({url:"wrongfile.txt",error:function(xhr){
            console.log("An error occured: " + xhr.status + " " + xhr.statusText);
        }});/*from w  w  w .j a  v  a  2 s . c om*/
    $.ajax();
    });
});
</script>
</head>
<body>

<p>Artists</p>
<div></div>

<button>test</button>

</body>
</html>

Related Tutorials