AJAX Example with JSONPlaceholder
JSONPlaceholder is a free fake API for testing and prototyping. Here's an example of using jQuery AJAX with JSONPlaceholder to fetch and display data.
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AJAX CRUD with JSONPlaceholder</title>
</head>
<body>
<h1>AJAX CRUD Operations</h1>
<!-- Create -->
<h2>Create Post</h2>
<input type="text" id="title" placeholder="Title">
<textarea id="body" placeholder="Body"></textarea>
<button id="create">Create Post</button>
<!-- Read -->
<h2>Posts</h2>
<button id="read">Get Posts</button>
<ul id="posts"></ul>
<!-- Update -->
<h2>Update Post</h2>
<input type="number" id="update-id" placeholder="Post ID">
<input type="text" id="update-title" placeholder="New Title">
<textarea id="update-body" placeholder="New Body"></textarea>
<button id="update">Update Post</button>
<!-- Delete -->
<h2>Delete Post</h2>
<input type="number" id="delete-id" placeholder="Post ID">
<button id="delete">Delete Post</button>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="script.js"></script>
</body>
</html>AJAX Code
Explanation
Output
Note
Last updated