Using fetch to asynchronously connect to server backend

Here’s an example:

    $('body').on('click', '#btnSavePendingPaymentInfo', function () {
        var SelectorID = $(this).attr('id');
        console.log(`Saving payment info`);
        csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
        console.log(`csrftoken: ${csrftoken}`);
        url = $("#UpdatePaymentModal").data('update-link');
        const request = new Request(
            url,
            { headers: { 'X-CSRFToken': csrftoken } }
        );
        var checkin_num = $('body').find("#CheckinNo").html();
        var HospitalID = $('body').find("#PatientIP").html();
        var amt_paid = $("#pending_amt_paid").val();



        // Build formData object.
        let formData = new FormData();
        formData.append('checkin_num', checkin_num);
        formData.append('HospitalID', HospitalID);
        formData.append('amt_paid', amt_paid);


        fetch(request, {
            method: 'POST',
            mode: 'same-origin',  // Do not send CSRF token to another domain.
            body: formData,
        }).then(function (response) {
            console.log(`Received server response.`);
            console.log(response);
            // text = response.statusText;
            response.text().then(
                text => $("#" + SelectorID).notify(text, { position: "right middle", className: 'success' })
            );

        });
    });