Answers for "javascript api request"

3

javascript http request

// Use these functions:

function _GET_REQUEST(url, response) {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }

  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      response(this.responseText);
    }
  };

  xhttp.open("GET", url, true);
  xhttp.send();
}

function _POST_REQUEST(url, params, response) {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }

  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      response(this.responseText);
    }
  };

  xhttp.open("POST", url, true);
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhttp.send(params);
}


// Use like:
_GET_REQUEST('http://url.com', (response) => {
	// Do something with variable response
  	console.log(response);
});
_POST_REQUEST('http://url.com', 'parameter=sometext', (response) => {
	// Do something with variable response
  	console.log(response);
});
Posted by: Guest on October-18-2020
1

http request javascript

function httpGetAsync(url, callback) {
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.onreadystatechange = function() { 
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
      callback(xmlHttp.responseText);
  }
  xmlHttp.open("GET", url, true); // true for asynchronous 
  xmlHttp.send(null);
}
Posted by: Guest on May-20-2020
2

api request

Request 
		 Request URL (ENDPOINT)
		 	http://54.158.178.13:8000/api/spartans

		 HTTP Methods|Verb  : GET POST PUT DELETE PATCH 
		 	
		 HEADER  : key value pair 
		 	Accept , Content-Type
		 
		 Query Parameters : key value pair right after ? 
		 	/api/spartans/search?gender=Male&nameContains=li
		 	mostly used to filter out the result according to 
		 	the cirteria provided here 

		 Path Parameters|Variable 
		 	/api/spartans/{id}  /api/spartans/:id
		 	used to identify single resource among list of resources

		 Request Body | Payload
		 	the data you are sending to the server
Posted by: Guest on December-04-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language