JSFiddle - React, Tailwind, and code Playground
JavaScript
function send (method, url, data)
{
var xhr = new XMLHttpRequest();
xhr.ontimeout = function()
{
alert('timeout');
}
xhr.onload = function()
{
if (xhr.readyState === 4)
{
if (xhr.status === 200)
{
alert('success');
}
else
{
alert('failed');
}
}
else
{
alert('failed');
}
};
try
{
xhr.timeout = 10000;
xhr.open(method, url, true);
xhr.send(data);
}
catch(er)
{
alert('failed');
}
}
send('POST', '/echo/jsonp/', null);