I am trying to find an example of HTTP post request in Typescript but can only find examples that use Angular. Could someone point me in the right direction to find this or post
Here is my very simple example to call GET or POST with Typescript only.
//-------------------------------------------------
// Simple function to GET or POST
function httpCall(method: string, url:string, data:any, callback:(result:any)=>any) {
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
if (callback) xhr.onload = function() { callback(JSON.parse(this['responseText'])); };
if (data != null) {
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(data));
}
else xhr.send();
}
Optional input data (the post body) and callback. The data and result are both assumed to be JSON.