How to Make a Simple jQuery AJAX Call on Link Click? Last Updated : 12 Nov, 2024 Comments Improve Suggest changes Like Article Like Report To make a simple jQuery AJAX call when a link is clicked, you can use jQuery's .click() method and the $.ajax() function to send a request and handle the response. Here's a basic example to demonstrate how this works:Example: jQuery AJAX Call on Link ClickHTML Structure: HTML <a href="#" id="myLink">Click me to send AJAX request</a> <div id="response"></div> <!-- Include jQuery --> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> Output:OutputjQuery AJAX Call on Link Click: JavaScript $(document).ready(function() { $('#myLink').click(function(event) { event.preventDefault(); // Prevent the default link behavior // Make an AJAX request $.ajax({ url: 'process.php', // Replace with your server-side script URL type: 'GET', // or 'POST' depending on your needs success: function(response) { // Display the response inside the #response div $('#response').html('Server Response: ' + response); }, error: function() { $('#response').html('An error occurred while processing the request.'); } }); }); }); Explanation:$('#myLink').click():Attaches a click event listener to the link with the ID myLink.event.preventDefault():Prevents the default behavior of the <a> element (which would typically cause a page reload or navigation).$.ajax():Sends an asynchronous HTTP request.url: Specifies the URL of the server-side script to handle the request (e.g., process.php).type: Specifies the request method ('GET' or 'POST').success: A callback function that handles the response when the request is successful.error: A callback function that handles errors if the request fails.Key Points:Replace 'process.php' with the appropriate URL of your server-side script that will process the request.You can modify the data sent with the request using the data property within the $.ajax() call, like so: JavaScript $.ajax({ url: 'process.php', type: 'POST', data: { key1: 'value1', key2: 'value2' }, success: function(response) { $('#response').html('Server Response: ' + response); } }); This example demonstrates how to make a simple jQuery AJAX call when a link is clicked, preventing default behavior, sending a request to the server, and displaying the response on the page Comment More infoAdvertise with us Next Article How to Make a Simple jQuery AJAX Call on Link Click? A anuragtriarna Follow Improve Article Tags : JavaScript Web Technologies Web QnA Similar Reads How to make a JSON call using jQuery ? Use the getJSON() function in jQuery to load JSON data. The getJSON() function uses a GET HTTP request to retrieve JSON-encoded data from the server. In this article, we will learn about the jQuery getJSON() function and its implementation through examples. Syntax: $(selector).getJSON(url, data, suc 3 min read How to set alert message on button click in jQuery ? Setting an alert message on a button click in jQuery means using jQuery to capture the button's click event and trigger a browser alert box. This alert displays a custom message to the user whenever the button is clicked.jQuery CDN Link: We have linked the jQuery in our file using the CDN link. < 1 min read How to add dbclick() on right click in jQuery? The jQuery dblclick() method is used to detect whenever a particular element is double-clicked. This method only detects left mouse button double clicks and not the right mouse button double clicks. In this article, we will see how to simulate the double right mouse click in jQuery. Approach: There 3 min read How to make a call-able link using HTML ? To make a callable link using HTML means creating a hyperlink that allows users to initiate a phone call directly from their devices. This is done using the <a> tag with the href attribute set to tel: followed by the phone number. When clicked, this link opens the phone dialer on supported dev 2 min read How to make ajax call from JavaScript ? Making an Ajax call from JavaScript means sending an asynchronous request to a server to fetch or send data without reloading the web page. This allows dynamic content updates, enhancing user experience by making the web application more interactive and responsive.There are multiple ways to make Aja 4 min read Like