In this article, we will discuss how to invoke API using the AJAX call. We use the AJAX call because it allows the user to update a web page without reloading the page, request data from a server after the page has loaded, receive data from a server after the page has loaded, and send the data to a server in the background.

 
The below HTTP verb is used to call a particular Web API call. Here is the mapping sequence.
    POST - Create
    GET - Read
    PUT - Update
    DELETE - delete

    var person = new Object();    
    person.name = $('#name').val();    
    person.surname = $('#surname').val();    
    $.ajax({    
        url: 'http://localhost:3413/api/person',    
        type: 'POST',    
        dataType: 'json',    
        data: person,    
        success: function (data, textStatus, xhr) {    
            console.log(data);    
        },    
        error: function (xhr, textStatus, errorThrown) {    
            console.log('Error in Operation');    
        }    
    });  


In the above code, we pass the person data to the API using the Post method.
 
You can call the API using the above code for different uses, like Delete record, Update record, and Get records using Get, Put, and Delete type keywords.

HostForLIFE.eu AJAX Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.