=
$ajax({
url:
type:
succcess:function (response){},
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AJAX Request Example</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Button click event handler
$('#getDataBtn').click(function() {
$.ajax({
url: 'https://jsonplaceholder.typicode.com/posts/1', // Example API endpoint
type: 'GET',
success: function(response) {
// Handle the successful response here
console.log(response);
$('#result').text(JSON.stringify(response));
},
error: function(xhr, status, error) {
// Handle errors here
console.error('Error:', error);
}
});
});
});
</script>
</head>
<body>
<button id="getDataBtn">Get Data</button>
<div id="result"></div>
</body>
</html>
=
No comments:
Post a Comment