Ajax

From rbachwiki
Revision as of 00:38, 26 October 2016 by Bacchas (talk | contribs) (Created page with "==Get Data == <pre> var xhttp = new XMLHttpRequest(); var url = 'https://jsonplaceholder.typicode.com/posts'; var method = 'GET'; xhttp.open(method, url); xhttp.onreadystatec...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Get Data

var xhttp = new XMLHttpRequest();
var url = 'https://jsonplaceholder.typicode.com/posts';
var method = 'GET';
xhttp.open(method, url);

xhttp.onreadystatechange = function(){
  if(xhttp.readyState == 4 && xhttp.status == 200){
    console.log(JSON.parse(xhttp.responseText));
    
  } else if(xhttp.readyState === XMLHttpRequest.DONE && xhttp.status !== 200)
  {
    console.log(xhttp.status);
  }
  
};

xhttp.send();

Back To Top- Home - Category