- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 ReactJS 完全陌生。
然后我按照这个tutorial在 YouTube 上,我按照每个步骤操作。
直到我发现我的代码出现类似 this 的错误
由于我刚接触 ReactJS 编程,我仍然不明白该怎么做,我该如何解决这个问题
本教程展示了如何使用 ReactJS 和 PostgreSQL 构建一个简单的 CRUD 应用
我在这里提供我的App.js代码
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
constructor(){
super();
this.state={
title: 'Simple Guestbook',
guestbooks: []
}
}
componentDidMount(){
console.log('Component has mounted')
}
addGuest(event){
event.preventDefault();
let data = {
guestname: this.refs.guestname.value,
guestaddress: this.refs.guestaddress.value
};
var request = new Request("http://localhost:3000/api/new-guest", {
method: 'POST',
headers: new Headers({'Content-Type': 'application/json'}),
body: JSON.stringify(data)
});
//xmlhttprequests
fetch(request)
.then(function(response){
response.json()
.then(function(data){
console.log(data)
})
})
}
render() {
let title = this.state.title;
return (
<div className="App">
<h1>Assalaamu'alaykum</h1>
<h2>{title}</h2>
<form ref="guestbookForm">
<input type="text" ref="guestname" placeholder="guest name"/>
<input type="text" ref="guestaddress" placeholder="guest address"/>
<button onClick={this.addGuest.bind(this)}>Add Guest</button>
</form>
</div>
);
}
}
export default App;
这是我的server.js代码:
let express = require('express');
let bodyParser = require('body-parser');
let morgan = require('morgan');
let pg = require('pg');
const PORT = 3000;
let pool = new pg.Pool({
port:5432,
password: 'qwerty',
database: 'guestbook',
max: 10,
host: 'localhost',
user: 'postgres'
});
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(morgan('dev'));
app.use(function(request, response, next) {
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.post('/api/new-guest', function(request, response){
console.log(request.body);
});
app.listen(PORT, () => console.log('Listening to Port '+ PORT));
我该怎么办?任何建议都会帮助我解决这个问题
谢谢...
最佳答案
使用箭头函数,
fetch(request)
.then((response) => {
return response.json()
}).then((data) => {
console.log(data)
})
关于javascript - ReactJS - 无法加载资源 : the server responded with a status of 404 (Not Found),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530751/
如何修复 Excel VBA 中的 Not Responding 错误? 我的代码是完美的,我没有收到任何错误,但在我运行它之后,我会看到 Excel VBA 的NOT RESPONDING 顶部并且
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: Keep app responsive during long task 在处理大型查询或长流程循环时如何避免“无响
这是我第一次遇到有人试图侵入我创建的网站。我可以做什么来阻止这些尝试? 顺便说一句,他们的 SQL 注入(inject)不可能起作用,而且我们拥有的任何数据都不能被正常使用该网站的任何人使用。 附加:
我的 java 进程停止响应。我尝试 jstack 但失败并出现以下错误。 21039: Unable to open socket file: target process not respondi
This question already has answers here: Closed 7 years ago. Possible Duplicate: Dismiss keyboard on
我不确定这是否重复,我尝试过的可能的补救措施无效。 (下面会提到) 我目前正在为我正在做的项目使用 Theme.AppCompat.NoActionBar 并且正在使用 android.support
这是一个简单的用户登录。我只是想了解这个概念。让我解释一下我的代码问题。这是我的表单: User: Password: check_login.php: Use
我正在创建一个线程,它可以控制所有程序过程消息并且不会卡住程序。我写了this code我得到了 program not responding。 有没有人有使用线程的经验可以帮助我? 最佳答案 Win
我将 Selenium 与 Python 结合使用。单击按钮时,我在 widows Python 中收到一条消息: Not responding in widows Python I have the
我有一个长时间运行的方法,必须在 UI 线程上运行。(Devex - gridView.CopyToClipboard()) 我不需要 UI 在复制时响应,我添加了启动画面,这样用户就不会感到无聊。
对于测试,使程序显示“无响应”的最简单方法是什么?中断 Windows 消息或将其置于无限循环中? 我试过一个简单的循环 while(true) 但这行不通。测试应用程序是 C# 控制台应用程序。它在
App里发生的最糟糕的事是弹出应用无响应”Application Not Responding” (ANR) 对话框.本课讲的是如何保持应用响应,避免ANR。 什么触发ANR 通常,系统会在应用
我们遇到一个客户运行我们基于 WPF 的程序的问题。他可以启动应用程序、创建新文档、在 TreeView 中导航菜单项以查看文档的不同部分、更改几乎(如果不是全部)我们的文本框值、将项目添加到列表(使
在VCL主线程中,我运行一个脚本,该脚本可能需要几分钟才能执行(这是一个还原数据库脚本)。 如果用户单击UI,则我的标题为“无响应”。 Application.ProcessMessages不起作用。
我这里有一个无意义的小脚本,我正在 MATLAB R2013b 中执行它: clear all; n = 2000; times = 50; i = 0; tCPU = tic; disp 'CPU:
我想将验证错误发送回另一个页面(添加),因此我的save操作具有以下功能: @Transactional(readOnly = false) def save(AddDomainCommand com
我正在构建一个 JavaFX 应用程序并使用 JOptionPane 来显示对话框 我遇到的问题之一是创建一个新对话框并且不在 5 秒左右关闭它会导致主 JavaFX 阶段进入“无响应”状态 在新线程
好吧,我尝试将信息从 servlet 发送到 jsp,所以我尝试使用 request.setAttribute() 和 respond.getRequestDispatcher("page.jsp")
我对代码进行排序有什么问题吗?当我打开程序时,我看到错误“程序未响应”。请检查我的代码。 void sorting(el_list **first) { el_list *newfirst =
出于测试目的,我需要编写一个程序,将著名的“应用程序未响应”消息显示在屏幕上。我不知道我怎么会激起这样的 react 。 最快、最简单的方法是什么?最好是 C/C++ 或 Java 最佳答案 在 Wi
我是一名优秀的程序员,十分优秀!