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

Latest commit

 

History

History
77 lines (48 loc) · 1.45 KB

README.md

File metadata and controls

77 lines (48 loc) · 1.45 KB

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);
    }
  };
}