Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

http request in js

//Using the javascript Fetch API 
//References: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

fetch('http://localhost:8080/test')
  .then((response) => response.json())
  .then((data) => console.log(data));
Comment

http get request js

function httpGetAsync(theUrl, callback) {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            callback(xmlHttp.responseText);
    }
    xmlHttp.open("GET", theUrl, true); // true for asynchronous 
    xmlHttp.send(null);
}

httpGetAsync("/api/v1/items", (res)=>{
  	// page content is in variable "res"
});
Comment

http request javascript

const requests = new XMLHTTPRequest();

requests.open('METHOD', url)
requests.send()

requests.onload = () => {
 if (requests.status == 200) {
   console.log('ok')
 } else {
 console.log('didnt work')
 }
}
Comment

http request javascript

function httpGetAsync(url, callback) {
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.onreadystatechange = function() { 
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
      callback(xmlHttp.responseText);
  }
  xmlHttp.open("GET", url, true); // true for asynchronous 
  xmlHttp.send(null);
}
Comment

js get request

document.addEventListener("DOMContentLoaded", function() {
    const xmlHttp = new XMLHttpRequest(),
        div = document.getElementById('music_all_ajax');
    xmlHttp.open("GET", '{{ route('music ') }}', false); // false for synchronous request
    xmlHttp.send(null);

    div.insertAdjacentHTML('afterbegin', xmlHttp.responseText);
});
Comment

Javascript make HTTP request

const xhr = new XMLHttpRequest();
JavaScriptCopy
Comment

Javascript make HTTP request

xhr.open(Method, URL[, Async]);
JavaScriptCopy
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular local storage 
Javascript :: strapi login api 
Javascript :: await inside map js 
Javascript :: vue select option get attribute 
Javascript :: samesite cookie nodejs 
Javascript :: react native use navigation outside component 
Javascript :: js cypress div text 
Javascript :: how to find the last item in a javascript object 
Javascript :: get a href value javascript 
Javascript :: inarray jquery 
Javascript :: number to binary javascript 
Javascript :: spacebar event listener 
Javascript :: node get current url 
Javascript :: date options js 
Javascript :: flutter circularprogressindicator 
Javascript :: nodejs recursively read directory 
Javascript :: url decode in javascript 
Javascript :: lazy loading pagination react npm 
Javascript :: chart js two y axis 
Javascript :: discord.js how to use subcommands 
Javascript :: nghide angular 10 
Javascript :: how to check what browser you are using javascript 
Javascript :: how to change background image for a webpage 
Javascript :: js fetch send json 
Javascript :: window closing event js 
Javascript :: return the next higher prime number javascript 
Javascript :: set image as background react 
Javascript :: jquery data attribute 
Javascript :: reverse a linked list javascript 
Javascript :: async await catch error 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =