markdown JS.JSON.RetrievingData.FetchAPI.v1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown JS.JSON.RetrievingData.FetchAPI.v1相关的知识,希望对你有一定的参考价值。

////////////////////////////
// Javascript and JSON
//
//     JSON is the standard of exchanging information
//     with remote servers / http servers.
//
//     Mechanism for transforming complex objects into
//     human readable string representations.
//
//     It was made to replace XML as the format for exchanging
//     data between servers (cleint / remote HTTP server.)
//
//     V.Popular - AJAX communications with http servers
//
//     Used for storing objects in LocalStorage. If we want to save
//     a javascript object, we will have to turn it into JSON, then save
//     it. When we read from the datastore, we retrieve the JSON,
//     and turn it back into an object. Note: LocalStorage is
//     the space reserved by the browser to be used as a small db for
//     the application. 
//
//     Schematic of Function:
// 
//     Storing Object in LocalStorage:
//        Object -> JSONstring -> Local Storage
//
//     Retrieving Object from LocalStorage:
//        LocalStorage -> JSONstring -> Object
//
//     1. object to JSON -> JSON.stringify(obj)
//     2. JSON to object -> JSON.parse(jsonString)


// ex 1 - simple int -> will return string int
var x = 3;
var JsonString1 = JSON.stringify(x);
console.log(JsonString1);
var JsonStringtoObj = JSON.parse(JsonString1);
console.log(JsonStringtoObj);


// Two major modules to fetch json data with ajax requests.
// The XHR2 API
// The Fetch API (Simpler)

////////////////////////////////////////////////
// FETCH API

function search() {
    var queryURL = "https://jsonplaceholder.typicode.com/users";
    fetch(queryURL)
      .then(function(response) {
          // response is a json string,
          // convert it to a pure JavaScript object
          // for the next 'then' callback.
          return response.json();
      })
      .then(function(users) {
          // users is a JavaScript object here
          console.log(users)
      })
      .catch(function(error) {
          console.log('Error during fetch: ' + error.message);
      });
}

console.log(search());
JS.JSON.RetrievingData.FetchAPI.v1
----------------------------------


A [Pen](https://codepen.io/Onlyforbopi/pen/rqNJwE) by [Pan Doul](https://codepen.io/Onlyforbopi) on [CodePen](https://codepen.io).

[License](https://codepen.io/Onlyforbopi/pen/rqNJwE/license).

以上是关于markdown JS.JSON.RetrievingData.FetchAPI.v1的主要内容,如果未能解决你的问题,请参考以下文章

转换rst到markdown总结

markdown [Markdown HowTo]作为Markdown语法的秘籍

python markdown干啥用的

markdown前端渲染

如何用markdown生成目录

markdown排版示例