目标:在函数中从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) 目前
newValue当用户单击 contentEditable 时<div>,它会存储一个,并newValue随着用户键入而更新。注意:我以这种方式设置此行为有两个主要原因:(1)我不想发送要在每次击键时保存的数据,以及(2)我计划使用此 div 的变体,其中检查每个输入以验证输入是否为数字。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) 我最近在我的AWS ec2 Ubuntu 16.04服务器上安装了 Ghost 1.8.4 和 Nginx 。当我加载我的博客站点时,它正确地将我带到了 Ghost 主页,从那里我登录到了 Ghost 管理员。在管理屏幕上,有一条消息要更新。
我跑ghost update在腻子里
更新似乎成功了,但是当我返回我的博客站点时,收到以下错误:
502 错误网关 nginx/1.10.3 (Ubuntu)
我去了我的ghost目录/var/www/ghost并尝试运行:
sudo service ghost start
但它返回:
Failed to start ghost.service: Unit ghost.service not found
并试图停止,返回Unit ghost.service not loaded。我是否从正确的位置运行命令?
在我的 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 样式表?
目前
我有一个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
我的表头中有一个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
javascript ×4
reactjs ×3
html ×2
async-await ×1
aws-lambda ×1
body-parser ×1
css ×1
express ×1
fetch ×1
ghost ×1
ghost-blog ×1
nginx ×1
promise ×1