I want to call a function during sending a request and after receiving response with every fetch() function using Vanilla JS. I saw that jquery ajax is providing some kind of $.ajaxsetup for doing this but I want to do it with Vanilla JS. Thanks in advance.
Advertisement
Answer
fetch
doesn’t have a feature like that. You could write a wrapper function though:
JavaScript
x
7
1
const myFetch = async (args) => {
2
do_before();
3
const result = await fetch(args);
4
do_after();
5
return result;
6
}
7
and then call that function instead of accessing fetch
directly.