.ajax({
success:function(result),
error:function(xhr),
}
vsfetch().then((e)=>function()) is even close to being the same, then we're just not even talking the same language
.ajax({
success:function(result),
error:function(xhr),
}
vsfetch().then((e)=>function()) is even close to being the same, then we're just not even talking the same language
Boom, same syntax if that's what you prefer.
J/K, the error status handling is not the same and the auto-deserialization isn't present. Not hard to add but it's harder to argue not to use a lib instead of copy-pasting 114 lines of niceties into each project.
You mean like response.json()?
const response = await fetch(...)
Bam, now you have the response without needing callbacks.
response.ok; // false
response.status; // 404
Um, okay, I get it. So to get the text content of the response, I just need to do response.text, right? No, you dummy, that's a function! You need to call response.text(), duh. It's so funny how an entire generation of front-end engineers just accepted this slop as acceptable API design. You can't fix the past, but thank God for (oh the irony) Microsoft and TypeScript.Fetch returning null on a network error just seems the worst possible design, as you don't get any information about why it failed. Raising an error or rejecting the promise seems an appropriate choice for fetch. It failed to reach any server, so it cannot produce a Response object -- but it can raise an error with failure details.