Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
/ xhr-CRUD Public archive

Demo of READ operation from xml-http-request

Notifications You must be signed in to change notification settings

DevelopmentGuide/xhr-CRUD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XML HTTP Requests

XMLHttpRequest is an API in the form of an object whose methods transfer data between a web browser and a web server. The object is provided by the browser's JavaScript environment.

Get started

  1. Open index.html and click on particular operations

  2. Refer console for details of both working and code

image

Screenshots

image

Structure

src
    Burgers

        - (Requires local database)

    GitHubAPI

        - (Requires GitHub API)

        - Get one field

        - Get array

    Local

        - (Burgers API alternative)

        - MessagesAPI

db1.json

db2.json

index.html

CRUD Operations

  • Create
  • Read
  • Update
  • Delete

READ

function gitUser() {
  var xhr = new XMLHttpRequest();
  var method = "GET";
  var URL = "https://api.github.com/users/pratikkabade";

  xhr.open(method, URL, true);

  xhr.send();

  xhr.onload = function () {
    if (xhr.status == 200) {
      const data = JSON.parse(xhr.response);
      console.log("success");

      const p = document.createElement("li");
      p.innerHTML = data.bio;
      document.getElementById("output").appendChild(p);
    }
  };
}