Skip to content

Instantly share code, notes, and snippets.

@dzsquared
dzsquared / ajax-with-promise.ts
Created July 24, 2018 15:12 — forked from floriankraft/ajax-with-promise.ts
HTTP Request with Promises in Typescript
getRequest(url: string): Promise<any> {
return new Promise<any>(
function (resolve, reject) {
const request = new XMLHttpRequest();
request.onload = function () {
if (this.status === 200) {
resolve(this.response);
} else {
reject(new Error(this.statusText));
}