javascript http get request
function makeRequest (method, url, data) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
if(method=="POST" && data){
xhr.send(data);
}else{
xhr.send();
}
});
}
//GET example
makeRequest('GET', "https://www.codegrepper.com/endpoint.php?param1=yoyoma").then(function(data){
var results=JSON.parse(data);
});
Also in JavaScript:
- empty array javascript
- how to make page scroll to the top jsx
- javascript all type of data
- add bootstrap to react app
- json minecraft
- set navigation drawer to open by default react native
- how to create alias in populate moongoose + nodejs
- react native vs flutter
- create json model online
- redirect to different page in javascript
- change object key name javascript es6
- closure in javascript
- jquery alert
- Unable to resolve "react-navigation-stack" react native
- horizontal cards react bootstrap
- $(...).autocomplete is not a function
- include partials ejs
- react native app slow lagging image
- riverSizes javascript
- mysql json extract escape
- functions in arrays javascript
- javascript redirect to another url example
- Regular Expressions: Find More Than the First Match
- explain js es6