Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript make async get request

var xhr = new XMLHttpRequest();
xhr.open("GET", "/bar/foo.txt", true);
xhr.onload = function (e) {
  if (xhr.readyState === 4) {
    if (xhr.status === 200) {
      console.log(xhr.responseText);
    } else {
      console.error(xhr.statusText);
    }
  }
};
xhr.onerror = function (e) {
  console.error(xhr.statusText);
};
xhr.send(null);
Comment

PREVIOUS NEXT
Code Example
Javascript :: regex for email validation 
Javascript :: get name jquery 
Javascript :: get all global variables javascript 
Javascript :: styling element using jquery 
Javascript :: javascript disable form 
Javascript :: javascript take last n elements of array 
Javascript :: js string to array 
Javascript :: array to string javascript 
Javascript :: create multiple collections in mongodb 
Javascript :: merge 2 dictionaries with same keys javascript 
Javascript :: notice before reload js 
Javascript :: queryselector name attribute 
Javascript :: ngswitchcase in angular 8 
Javascript :: remove local storage item 
Javascript :: time taken for a function javascript 
Javascript :: java gson string to json 
Javascript :: js check if is array 
Javascript :: jquery telephone input mask 
Javascript :: delete with body angular 
Javascript :: capitalize first letter of string javascript 
Javascript :: firestore set a document 
Javascript :: javascript mouse up mouse down 
Javascript :: redux devtools extension 
Javascript :: express public folder 
Javascript :: javascript loop and array 
Javascript :: fetch await reactjs 
Javascript :: js add content to script tag 
Javascript :: iterate over array of objects javascript 
Javascript :: how to reverse a string in javascript without using reverse method 
Javascript :: jquery attr 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =