Ad Code

Responsive Advertisement

How to make an ajax call in jquery ?

 

 Ajax call in jquery :-


1.Import jquery in html file:


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

2. Place code in html body tag:

<script>

//payload

var requireData = JSON.stringify
    ({
       "username": "name"
    });
$.ajax({
    url: "url",
    method: "post",
    contentType: "application/json",
    dataType: 'json',
    data: requireData, // request body
    success: function (res, xhr) {

    // place success code here
    console.log("response  is: ", res)
   
       },
    error: function (xhr) {
  // your error message goes here
    }
});

</script>
Reactions

Post a Comment

0 Comments