How to do ajax PATCH?

115
March 07, 2022, at 05:00 AM

I am trying to do ajax Patch. But it's not working. I am following this link https://stackoverflow.com/questions/38945677/using-jquery-patch-to-make-partial-update

My code-

<form onsubmit="save(document.getElementById('id').value)">
    .... removed for brevity
    <input type="hidden" id="id">
    <input type="number" id="sa">
    .... removed for brevity
</form>

My javascript-

function save(id) {
   
    var patch = [
        { 
            "id": id,
            ....
            "sactionedAmount": document.getElementById('sa').value, 
            ....
        }
    ];
    $.ajax({
        type: 'PATCH',
        url: url + "payout-requests/" + id,
        data: JSON.stringify(patch),
        processData: false,
        contentType: 'application/json-patch+json',
        dataType: 'json',
        async: false,
        crossDomain: true,
        headers: {
            "Authorization": 'Bearer ' + token
        },
        success: function (result){
            alert("Result = " + JSON.stringify(result));
        },
        error: function(result) { 
            alert("Error: " + JSON.stringify(result)); 
        }  
    });
}

It is showing the alert of success function. But data is not updated. Thanks for any help.

Rent Charter Buses Company
READ ALSO
Change .html URL depending on the active div

Change .html URL depending on the active div

I have two html pages: index1html and index2

90
Back button of the browser is not working + content is not loading if don&#39;t click on refresh button

Back button of the browser is not working + content is not loading if don't click on refresh button

I am really new to JS/jQuery/Ajax I have this codeI want that the content in article tag change but to keep all the rest (header, menu and footer) stays the same while the user click on a link of on the website

105
`element.innerHTML` not working as expected

`element.innerHTML` not working as expected

I have a form on whose submission, will post a URL, and the server returns a HTML string which should be appended to the form

96
How to call method Model in jQyery

How to call method Model in jQyery

I have a path method in the Course model

111