Jquery Ajax Request Example Tutorial

By Hardik Savani November 5, 2023 Category : jQuery

Hello Friends,

In this post, we will learn jquery ajax request example. you will learn jquery post ajax json data. I would like to show you jquery get ajax response json example. step by step explain jquery $.ajax post example.

In this example, we use the $.ajax() function to make an AJAX request to the URL "example.com/api/data" using the POST method. The success function is called when the request is successful, and it takes the response data as its argument. The error function is called if there is an error with the request, and it takes the xhr (XMLHttpRequest) object, the status, and the error message as its arguments.

You can customize the AJAX request by setting additional options in the $.ajax() function, such as the data to send in the request, the data type of the response, and the headers to include in the request.

Example:

<html lang="en">

<head>

<title>JQuery Ajax Demo</title>

<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

</head>

<body>

<button class="ajax">Click Here</button>

<script type="text/javascript">

$(".ajax").click(function(){

$.ajax({

url: "example.com/api/data",

dataType: "json",

type: "POST",

data: {"id":"10"},

success: function (data) {

alert(data);

},

error: function() {

alert('Error.');

}

});

});

</script>

</body>

</html>

I hope it can help you...

Tags :
Shares