Friday, 24 September 2021

converting an fetch api call to ajax

i am using a code from a site where onsubmit the call is made and a call is made

$(":submit").click(async (event) => {

i am not aware of this syntax.

my example using the simple $.ajax call and making a post call to the page

so the above function is like this

$(":submit").click(async (event) => {
        event.preventDefault();
        let response = await fetch("page.cfm");
        const reader = response.body.getReader();
        const len = response.headers.get("Content-Length") * 1;

my ajax call is like this

$.ajax({
                url: "page.cfm",
                cache: false,
                data : $('#form').serialize(),
                method: "post",
                beforeSend: function() {
                    $('div.results').html('Please wait');
                },
                success: function(response){
                    $('div.results').html(response);
                }

how can i format the above to my ajax call



from converting an fetch api call to ajax

No comments:

Post a Comment