小编Wro*_*ski的帖子

fetch() POST 请求到 Express.js 生成空体 {}

目标:在函数中从HTML发送一些定义的字符串数据,fetch()例如“我的数据”


我的代码:

HTML

<!DOCTYPE html>
<html>
<body>

<script type="text/javascript">
    function fetcher() {
      fetch('/compute',
        {
          method: "POST",
          body: "MY DATA",
          headers: {
            "Content-Type": "application/json"
          }
        }
      )
      .then(function(response) {
        return response.json();
      })
      .then(function(myJson) {
        console.log(myJson);
      });
    }
</script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

服务器.js

var express = require("express");
var app     = express();
var compute = require("./compute");
var bodyParser = require("body-parser");

//not sure what "extended: false" is for
app.use(bodyParser.urlencoded({ extended: false }));

app.post('/compute', (req, res, next) => {
    console.log(req.body);
    var …
Run Code Online (Sandbox Code Playgroud)

javascript fetch express body-parser

19
推荐指数
2
解决办法
1万
查看次数

React:编辑 contentEditable div 时如何保持插入符号位置?

目前

  1. 我有一个 react 组件,newValue当用户单击 contentEditable 时<div>,它会存储一个,并newValue随着用户键入而更新。注意:我以这种方式设置此行为有两个主要原因:(1)我不想发送要在每次击键时保存的数据,以及(2)我计划使用此 div 的变体,其中检查每个输入以验证输入是否为数字。
  2. newValue发送时,要保存<div>失去焦点,然后道具的状态复位。

问题

onChangeHandler可编辑 div 中插入符号的位置移动到左侧。这导致击键123456显示为654321

代码:

class Input extends Component {

  constructor(props) {
    super(props);
    this.state = {
      //newValue input by user
      newValue : undefined
    }
  }

  //handler during key press / input
  onChangeHandler = event => {
    let targetValue =  event.currentTarget.textContent;
    this.setState({"newValue": targetValue})
  }

  //handler when user opens input form
  onBlurHandler = event => {
    //some …
Run Code Online (Sandbox Code Playgroud)

html javascript reactjs

9
推荐指数
1
解决办法
4856
查看次数

Ghost 1.8.7更新后出现“502 Bad Gateway”是什么原因

我最近在我的AWS ec2 Ubuntu 16.04服务器上安装了 Ghost 1.8.4 和 Nginx 。当我加载我的博客站点时,它正确地将我带到了 Ghost 主页,从那里我登录到了 Ghost 管理员。在管理屏幕上,有一条消息要更新。

我跑ghost update在腻子里

更新似乎成功了,但是当我返回我的博客站点时,收到以下错误:

502 错误网关 nginx/1.10.3 (Ubuntu)

  1. 有谁知道这个错误的可能原因以及如何解决?
  2. 我查看了一些帖子,建议我应该在更新前关闭 Ghost。如果这是真的,我的 Ghost 安装现在是否已损坏?
  3. 我去了我的ghost目录/var/www/ghost并尝试运行:

    sudo service ghost start

    但它返回:

    Failed to start ghost.service: Unit ghost.service not found

    并试图停止,返回Unit ghost.service not loaded。我是否从正确的位置运行命令?

nginx ghost-blog ghost

8
推荐指数
2
解决办法
3448
查看次数

React 类样式从 css 样式表不起作用

在我的 React 应用程序中,我尝试通过将样式分配给类来从 CSS 样式表加载 html 元素的样式。

我可以获得元素的样式,例如 h2、p、td、working

问题:

我无法为课程设置样式。

--- 更新:下面的代码似乎正在工作,我不确定是什么导致它之前失败。如果可以的话我会删除这个问题。感谢那些帮助过的人——

应用程序.js

import React, { Component } from 'react';
import './App.css';

class App extends Component {
  constructor(props) {
    super();
    }
  }

  render() {
    return (
      <div className="App">
        <div className="hide_me">
          <h2>This text should not be visible because it has className "hide_me"</h2>
        </div>
      </div>
    );
  }
}

export default App;
Run Code Online (Sandbox Code Playgroud)

应用程序.css

h2 {
  color: red;
}

.hide_me {
  display: none;
}
Run Code Online (Sandbox Code Playgroud)

目前的行为

我看到应该隐藏的红色文本,即 在此输入图像描述

预期行为

没有文字!


有没有一种解决方案可以让我在不安装新模块的情况下使用 CSS 样式表?

css reactjs

6
推荐指数
1
解决办法
4万
查看次数

为什么我的 await lambda.invoke 函数多次调用 lambda?

目前

我有一个lambdaX调用另一个lambdaY

拉姆达 X:

"use strict";

const AWS = require('aws-sdk');
AWS.config.region = 'ap-southeast-2';
var lambda = new AWS.Lambda();

exports.handler = async (event) => {

  //the final return
  var dataToSave = []

  //data to be added to array
  let returnLoad;

  var params = {
    FunctionName: 'lambdaY', // the lambda function we are going to invoke
    InvocationType: 'RequestResponse',
    LogType: 'Tail', //Set to Tail to include the execution log in the response.
  };

  try {
    await lambda.invoke(params, function(err, data) …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-web-services promise async-await aws-lambda

2
推荐指数
1
解决办法
411
查看次数

如何从表头的反应onClick事件中获取event.target.name(th)

我的表头中有一个onClick事件,用于对表进行排序。我需要将表头 html 元素名称传递给我的 onclick 处理程序。

处理程序的简化版本如下所示:

html:

<table>
  <tbody>
    <tr>
      <th name='name' value='test' onClick=onClickhandler(event)> Click me </th>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

js:

  onClickhandler = event => {
      console.log("Event target name = " + event.target.name);
  }
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/vaf5sutn/4/

问题

上面的代码作为日志返回Event target name = undefined

预期的

控制台日志应该返回 Event target name = name

html javascript reactjs

1
推荐指数
1
解决办法
1481
查看次数