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 :: javascript delete row by id 
Javascript :: create paragraphs with js in html 
Javascript :: js get string byte size 
Javascript :: LogBox 
Javascript :: javascript get date midnight today 
Javascript :: how to use componentdidmount in functional component 
Javascript :: generate random alphanumeric string javascript 
Javascript :: how to get file extension in javascript last index 
Javascript :: js get all iframes 
Javascript :: larger text console javascript 
Javascript :: import json typescript 
Javascript :: addAtribute 
Javascript :: jquery create element 
Javascript :: webkit-media-controls-timeline apply by jquery 
Javascript :: react native google play this device does not support 
Javascript :: c++ switch 
Javascript :: download file axios nodejs 
Javascript :: MongoServerSelectionError: connect ECONNREFUSED ::1:27017 
Javascript :: javascript keep only letters in string 
Javascript :: js find key by value in object 
Javascript :: chartjs line disable shadow 
Javascript :: how to get the contract address from the contract instance web3js 
Javascript :: var socket = io(); reconnect 
Javascript :: how to terminate a program in js 
Javascript :: javascript date get current date 
Javascript :: jquery datetimepicker format 
Javascript :: double matrix iteration in react 
Javascript :: generate random int js 
Javascript :: js get environment variable 
Javascript :: js set cookie 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =