Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

xmlhttprequest javascript

let xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function(){
    if(this.readyState === 4 && this.status === 200)
      {
        document.getElementById('response-div').innerHTML = this.responseText
      }
    }
	//get request with params
    xhr.open('GET', 'example?param1=true&param2=2');
  xhr.send();
});
Comment

js xmlhttprequest get request

// create request
const request = new XMLHttpRequest();
// function to handle result of the request
request.addEventListener("load", function() {
	// if the request succeeded
	if (request.status >= 200 && request.status < 300) {
		// print the response to the request
		console.log(request.response);
    }
});
// open the request
request.open("GET", "someurl");
// send the request
request.send();
Comment

xmlhttprequest javascript

function reqListener () {
  console.log(this.responseText);
}

var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("GET", "http://www.example.org/example.txt");
oReq.send();
Comment

xmlhttprequest js

var url = "https://jsonplaceholder.typicode.com/posts";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
	if (xhr.readyState === 4) {
    	console.log(xhr.status);
        console.log(xhr.responseText);
    }
};
xhr.send();
Comment

javascript xmlhttprequest

// note: following are the shortest examples
// synchronous request, will block main thread
function requestSync(url) {
	var xhr = new XMLHttpRequest();
	xhr.open("GET", url, false);
	xhr.send();
	return xhr.responseText;
};
console.log(requestSync("file.txt"));

// async
function requestAsync(url) {
	return new Promise(function (resolve, reject) {
		var xhr = new XMLHttpRequest();
		xhr.open("GET", url);
		xhr.onload = () => resolve(xhr.response);
		xhr.send();
	});
}
requestAsync("file.txt").then((res) => console.log(res));
Comment

PREVIOUS NEXT
Code Example
Javascript :: react font awesome 
Javascript :: how to show 1 day ago in javascript 
Javascript :: js C:fakepath 
Javascript :: how to check all elements in array includes in another array javascript 
Javascript :: arabic regex javascript 
Javascript :: vue dynamic route push with params 
Javascript :: javascript array add front 
Javascript :: javascript Using Math.min() on an Array 
Javascript :: angular http put 
Javascript :: parent of heap node 
Javascript :: jquery google 
Javascript :: vue axios catch error 
Javascript :: how to change user password firebase 
Javascript :: javascript pluck from array of objects 
Javascript :: route component with props 
Javascript :: await in angular 8 
Javascript :: express uncaughtException 
Javascript :: how to trigger on input event in javascript 
Javascript :: js audio stream player 
Javascript :: change index array javascript 
Javascript :: how to list node process 
Javascript :: What is the syntax to export a function from a module in Node.js 
Javascript :: datatables filter with math functions 
Javascript :: eslint ignorel ine 
Javascript :: iterate over list array in solidity 
Javascript :: react-router-dom redirect 
Javascript :: react native image auto height 
Javascript :: jspdf pdf from html 
Javascript :: canvas js filter greyscale 
Javascript :: sleeping in js 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =