Test name | Executions per second |
---|---|
jQuery test case | 23569.2 Ops/sec |
Vanilla JS test case | 28557.7 Ops/sec |
<script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
$.ajax({
type: 'POST',
url: "http://vanilla-js.com/path/to/api",
data: {'banana': 'yellow'},
success: (data) = {},
});
const sendAjax = (url, data, callback) => {
fetch(url, {
method: 'POST',
body: new URLSearchParams(data),
}).then((response) => {
const contentType = response.headers.get("content-type");
if (contentType && contentType.indexOf("application/json") !== -1) {
return response.json().then(data => {callback(data)});
} else {
return response.text().then(text => {callback(text)});
}
});
}
sendAjax('http://vanilla-js.com/path/to/api', {'banana': 'yellow'}, (data) => {});