Difference between revisions of "Ajax"

From rbachwiki
Jump to navigation Jump to search
(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...")
 
Line 1: Line 1:
== Setting Up Ajax Request ==
1. Setup the Request
var httpRequest = new XMLHttpRequest();
2. Method type
var method = 'GET'
3. URL or location of local file
-var url = 'filename.txt'
-var url = 'https://jsonplaceholder.typicode.com/posts';
==Get Data ==
==Get Data ==
<pre>
<pre>

Revision as of 15:28, 15 November 2016

Setting Up Ajax Request

1. Setup the Request

var httpRequest = new XMLHttpRequest();

2. Method type

var method = 'GET'

3. URL or location of local file

-var url = 'filename.txt'
-var url = 'https://jsonplaceholder.typicode.com/posts';

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