Jquery AJAX Post Request REST API

We are going to make Jquery form data ajax post request.

Basically we have used jquey ajax to make our api call which is of form data type  and the response we are going to get is in json format.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
      var formDataSet;
    formDataSet = new FormData();
    formDataSet.append('mobile_telephone',6974512397);
    formDataSet.append('password',123456);
   $.ajax({
        url: 'https://testserver.com/api/login',
        headers: {
            'Authorization':'testauth',
        },
        data: formDataSet,
        processData: false,
          contentType: false,
        type: 'POST',
        success: function(data){
          console.log('succes: '+data);
        }
      });
  });
});
</script>
</head>
<body>
<h2>AJAX REST-API Post Request(form-data)</h2>
<button>Get External Content</button>
</body>
</html>

Response

Leave a reply

your email address will not be published. required fields are marked *

Name *
Email *
Website