我现在正在做React教程,并想知道ajax调用中的绑定.为什么我们需要在ajax调用中绑定它以获得成功和错误?显然,当我删除绑定时,该函数将抛出一个错误.我们是否使用绑定,因为我们this.setState在函数中有需要正确的引用?
// tutorial13.js
var CommentBox = React.createClass({
getInitialState: function() {
return {data: []};
},
componentDidMount: function() {
$.ajax({
url: this.props.url,
dataType: 'json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList data={this.state.data} />
<CommentForm />
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud) 我一直在抓住这个超时问题并希望得到一些帮助.我有一个http请求可能需要2.5分钟才能返回响应.我在Angular中处理超时处理3分钟,NodeJS处理3分钟.我的nginx设置有200秒超时,我的Elastic Load Balancing连接超时设置为4分钟.但是,我一直在2分钟内看到502坏网关nginx 1.4.6(Ubuntu)错误.有没有我错过超时的部分?
我的nginx设置:
server {
listen 80;
server_name;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://localhost:8060;
proxy_redirect off;
proxy_connect_timeout 200s;
proxy_send_timeout 200s;
proxy_read_timeout 200s;
send_timeout 200s;
}
#Handle protected assets using 'internal' directive documented here: https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/
location /protected {
internal;
expires -1;
}
}
Run Code Online (Sandbox Code Playgroud)
我的NodeJS设置正在使用connect-timeout
var timeout = require('connect-timeout');
app.use(timeout(300000));
Run Code Online (Sandbox Code Playgroud) 我的版本:反应:16.0.0 反应传单:1.6.6
我试图将图层控制器添加到我的地图中。有两层,每层都包含多个标记。这是我尝试做的一个例子。
import React, { Component } from 'react'
import { render } from 'react-dom'
import { Map, TileLayer, Circle, Marker, Popup, LayersControl, LayerGroup } from 'react-leaflet'
class SimpleExample extends Component {
constructor() {
super()
this.state = {
lat: 51.505,
lng: -0.09,
zoom: 3,
radius: 0
};
this.onClick1 = this.onClick1.bind(this);
this.onClick2 = this.onClick2.bind(this);
}
getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
onClick1(){
this.setState({radius: this.getRandomArbitrary(100, 800)});
}
onClick2(){
this.setState({radius: 0});
}
renderFirst() {
var result …Run Code Online (Sandbox Code Playgroud)