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 :: save image on cloudinary 
Javascript :: graphql json schema 
Javascript :: sveltekit redirect 
Javascript :: how to validate date in react 
Javascript :: break loop after time javascript 
Javascript :: puppeter loop 
Javascript :: javascript find ip and information 
Javascript :: javascript error null 
Javascript :: currying function callback javascript 
Javascript :: npm mongoose findorcreate 
Javascript :: chart js clear out chart 
Javascript :: angular conditional tooltip 
Javascript :: class keyword es6 
Javascript :: js xor 
Javascript :: convert excel date to javascript date 
Javascript :: Supported by YAML but not supported by JSON: 
Javascript :: js loop array back 
Javascript :: join string js with and at the last item 
Javascript :: JSON to Ruby Hash Parser 
Javascript :: 35,2 + 29,4 
Javascript :: get id value in javascript 
Python :: install matplotlib conda 
Python :: angle names matplotlib 
Python :: python get current file location 
Python :: pandas convert string from INT TO str 
Python :: dotenv python 
Python :: how to install pyaudio in python 
Python :: httpie on windows 
Python :: reset_index pandas 
Python :: ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost) 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =