0
我想通过ajax获取json,如果我的响应变量是可以接受的使用react路由器重定向。我怎样才能做到这一点?ReactJs重定向状态变量
successRedirect(){
if (this.responseCode.equals("what I need")) {
router.transitionTo('/')
}
}
createCheckout() {
$.ajax({
url: "someurl",
dataType: 'json',
type: 'POST',
cache: false,
data: this.data,
success: function(response) {
this.setState({
response: response,
responseCode: response.result.code
});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
})
}
功能必须在做出响应后调用。例如,我有这样的代码,并在呈现响应取并在一段时间后显示:
render(){
return (
<div>
<div>Response - {this.state.responseCode}</div>
</div>
);
}
我不明白这一点..所以调用'success'功能? – azium
我得到了undefind this.responseCode – TeodorKolev
你是不是指'this.state.responseCode'? – azium