Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从API获取()数据和从API获取()数据是否相同?_Javascript_Node.js_Reactjs - Fatal编程技术网

Javascript 从API获取()数据和从API获取()数据是否相同?

Javascript 从API获取()数据和从API获取()数据是否相同?,javascript,node.js,reactjs,Javascript,Node.js,Reactjs,我有一个任务:使用GET方法从中获取api信息。我还被告知只使用:Javascript/Reactjs 然而,无论我在哪里搜索,我都只能获取数据。这两个是同一件事吗?还是我看错了教程 import React, { Component } from 'react'; class App extends Component { constructor(props) { super(props); this.state = { items: [], i

我有一个任务:使用GET方法从中获取api信息。我还被告知只使用:Javascript/Reactjs

然而,无论我在哪里搜索,我都只能获取数据。这两个是同一件事吗?还是我看错了教程

import React, { Component } from 'react';

class App extends Component {

  constructor(props) {
    super(props);
    this.state = {
      items: [],
      isLoaded: false,
    }
  }

  componentDidMount() {
    fetch('https://jsonplaceholder.typicode.com/users')
      .then(res => res.json())
      .then(json => {
        this.setState({
          isLoaded: true,
          items: json,
        })
      });
  }

  render() {

    var { isLoaded, items } = this.state;

    if (!isLoaded) {
      return <div>Loading...</div>
    }
    else {
      return (
        <div className="App">
          <ul>
            {items.map(item => (
              <li key={item.uid}>
                Name: {item.name} | Email:{item.email}
              </li>
            ))};
          </ul>
        </div>
      );
    }
    
  }

}

export default App;
import React,{Component}来自'React';
类应用程序扩展组件{
建造师(道具){
超级(道具);
此.state={
项目:[],
isLoaded:false,
}
}
componentDidMount(){
取('https://jsonplaceholder.typicode.com/users')
.then(res=>res.json())
。然后(json=>{
这是我的国家({
isLoaded:是的,
项目:json,
})
});
}
render(){
var{isLoaded,items}=this.state;
如果(!已加载){
返回加载。。。
}
否则{
返回(
    {items.map(item=>(
  • 名称:{item.Name}电子邮件:{item.Email}
  • ))};
); } } } 导出默认应用程序;
它们是可互换的,作为该领域的一个技术术语,“从api获取数据”和“从api获取数据”的含义是相同的

现在,在javascript中,我们使用与api交互,使用诸如
GET
HEAD
POST
DELETE


不幸的是,我不知道有哪一个页面或存储库列出了这些行话,它们是可以互换的,因为作为该领域的技术行话,“从api获取数据”和“从api获取数据”的含义是相同的

现在,在javascript中,我们使用与api交互,使用诸如
GET
HEAD
POST
DELETE


不幸的是,我不知道列出这些行话的页面或存储库Fetch是一个javascript API,用于在web上发出XHR请求(通常用于与API交互)

但是GET是一个HTTP动词。主要或最常用的HTTP动词(或方法,如正确调用)是POST、GET、PUT、PATCH和DELETE。这些操作分别对应于创建、读取、更新和删除(或CRUD)操作

要了解有关这些方法的更多信息,请阅读建筑风格和
基于网络的软件架构设计由Roy Fielding博士或众所周知的Roy Fielding论文撰写,该论文描述了web的RESTful性质以及这些HTTP动词的使用

Fetch是一个javascript API,用于在web上发出XHR请求(通常用于与API交互)

但是GET是一个HTTP动词。主要或最常用的HTTP动词(或方法,如正确调用)是POST、GET、PUT、PATCH和DELETE。这些操作分别对应于创建、读取、更新和删除(或CRUD)操作

要了解有关这些方法的更多信息,请阅读建筑风格和 基于网络的软件架构设计由Roy Fielding博士或众所周知的Roy Fielding论文撰写,该论文描述了web的RESTful性质以及这些HTTP动词的使用

fetch()是发出请求的工具……它们可以是GET、POST、PUT、DELETE、HEAD、PATCH等。fetch()是发出请求的工具……它们可以是GET、POST、PUT、DELETE、HEAD、PATCH等
let promise = fetch(url, {
  method: "GET", // POST, PUT, DELETE, etc.
  headers: {
    // the content type header value is usually auto-set
    // depending on the request body
    "Content-Type": "text/plain;charset=UTF-8"
  },
  body: undefined // string, FormData, Blob, BufferSource, or URLSearchParams
  referrer: "about:client", // or "" to send no Referer header,
  // or an url from the current origin
  referrerPolicy: "no-referrer-when-downgrade", // no-referrer, origin, same-origin...
  mode: "cors", // same-origin, no-cors
  credentials: "same-origin", // omit, include
  cache: "default", // no-store, reload, no-cache, force-cache, or only-if-cached
  redirect: "follow", // manual, error
  integrity: "", // a hash, like "sha256-abcdef1234567890"
  keepalive: false, // true
  signal: undefined, // AbortController to abort request
  window: window // null
});