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

// 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 :: Ts get first string char 
Javascript :: react native shaddow 
Javascript :: redux useselector 
Javascript :: convert array string to number 
Javascript :: find only duplicate data javascript object 
Javascript :: get number from range line js 
Javascript :: how to make required field in jquery false 
Javascript :: GET req with js 
Javascript :: We often use anonymous functions as arguments of other functions. For example: 
Javascript :: jquery validator no space 
Javascript :: jquery addeventlistener 
Javascript :: js is date 
Javascript :: require is undefined 
Javascript :: javascript bind key to button 
Javascript :: javascript object destructuring rename 
Javascript :: js canvas rectangel 
Javascript :: f string javascript 
Javascript :: how to find the index of a value in an array in javascript 
Javascript :: javascript settimeout loop 
Javascript :: javascript is a string numeric 
Javascript :: csrf token method 
Javascript :: string.find javascript 
Javascript :: only allow numbers in text input in js 
Javascript :: angular goto top of page 
Javascript :: store data in array jquery 
Javascript :: org.json.JSONException: End of input at character 0 of 
Javascript :: nodejs check if express started 
Javascript :: vue js cdn link 
Javascript :: javascript remove trailing slash 
Javascript :: Shuffle a Sting in JavaScript 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =