Do you know How to use Jquery Ajax ?
jQuery’s AJAX syntax allows you to make asynchronous HTTP requests to a server and handle the response using JavaScript.
Example:
<!DOCTYPE html> <html> <head> <title>jQuery AJAX Example</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <button id="load-data">Load Data</button> <div id="result"></div> <script> $(document).ready(function () { // Event handler for the button click $("#load-data").click(function () { // Make an AJAX request $.ajax({ url: "https://api.example.com/data", // URL of the server endpoint method: "GET", // HTTP method (GET, POST, etc.) dataType: "json", // Expected data type of the response success: function (data) { // Function to handle the successful response $("#result").html("Received data: " + JSON.stringify(data)); }, error: function (xhr, status, error) { // Function to handle errors console.error("Error:", error); }, }); }); }); </script> </body> </html>
Leave a Reply