Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

xml http request

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
       // Typical action to be performed when the document is ready:
       document.getElementById("demo").innerHTML = xhttp.responseText;
    }
};
xhttp.open("GET", "filename", true);
xhttp.send();
Comment

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

// 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

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

XMLHttpRequest object

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

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

PREVIOUS NEXT
Code Example
Javascript :: react hook form reset 
Javascript :: react bootstrap carousel caption placement top 
Javascript :: create csv file javascript 
Javascript :: npm react copy to clipboard 
Javascript :: javascript next month from date 
Javascript :: react native npm run start port 
Javascript :: encrypt decrypt javascript 
Javascript :: javascript calculate percentage to pixel 
Javascript :: default selected radio button angular material 
Javascript :: json stringify close circle 
Javascript :: how to get element by id in node js 
Javascript :: list javascript 
Javascript :: js custom event 
Javascript :: discord client.send_message js 
Javascript :: react footer 
Javascript :: javascript today date in epoch 
Javascript :: forming an object with reduce 
Javascript :: Javascript removing duplicates in array 
Javascript :: timestamp convert moment vue 
Javascript :: javascript inject html 
Javascript :: filter in array function 
Javascript :: Update a property of an object of an array 
Javascript :: string json to class c# 
Javascript :: javascript merge array 
Javascript :: textalignvertical not working in ios react native 
Javascript :: install javascript kali linux 
Javascript :: get date in specific timezone 
Javascript :: html get class property 
Javascript :: new line javascript 
Javascript :: react bootstrap form select 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =