AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening.
The ajaxSuccess
event is only called if the request is successful. It is essentially a type function that’s called when a request proceeds.
The function takes three parameters, namely:
The data returned from the server, formatted according to the dataType parameter, or the dataFilter callback function.
A string describing the status.
The jqXHR object.
The success method can take an array of functions as well. In this case, all functions would be called one by one.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url: "Test_success.txt", success: function(result){
$("#newid").html(result);
}});
});
});
</script>
</head>
<body>
<div id="newid"><h2>Welcome to Jqeury</h2></div>
<button>New Button</button>
</body>
</html>
In the code above, the success method takes a result
function as a parameter and executes once the request is successful. This request is caused when the New Button
is clicked.
Free Resources