How to send data in Ajax with GET method using jQuery
jQuery
October 29, 2023
To send an AJAX request using jQuery with the GET method, you can use the $.ajax() function. Here is an example of how you can use this function to send a GET request with data:
<script>
$.ajax({
type: 'GET',
url: 'http://www.example.com/',
data: {
// data to be sent to the server
},
success: function(response) {
// handle the response
}
});
</script>
This function takes an object as an argument, where you can specify the request type (in this case, GET), the URL to send the request to, and any data to include in the request. You can also specify a success callback function to handle the response from the server.
Alternatively, you can use the $.get() function, which is a shorthand method for sending a GET request with jQuery. Here is how you can use this function:
<script>
$.get('http://www.example.com/', {
// data to be sent to the server
}, function(response) {
// handle the response
});
</script>
Both $.ajax() and $.get() allow you to send AJAX requests with the GET method using jQuery. You can use either method depending on your specific needs and preferences.
Admin
About Author
A full stack web developer specializing in frontend and backend web technologies. With a wealth of experience in building dynamic and robust web applications, he brings expertise and insights to his articles, providing valuable guidance and best practices for fellow developers. Stay tuned for more useful content.
Share the good stuff on social media and earn appreciation.