0
私はAJAX経由でJSONを取得しようとしています
にリダイレクトし、私の応答変数がある場合は許容リダイレクトルータを使用して反応させます。それをどうすれば実現できますか?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)
})
}
応答を受け取った後に関数を呼び出す必要があります。たとえば、私はこのコードを持っているし、応答をレンダリングするには、いくつかの時間後に撮影して示されている:
if (this.responseCode.equals("what I need")) {
this.setState
経由で追加されます
アイテムで使用できます。
render(){
return (
<div>
<div>Response - {this.state.responseCode}</div>
</div>
);
}
私はそれを取得しないとの比較を行うので、 'SUCCESS'で関数を呼び出すことができますか? – azium
私はundefind this.responseCodeを得た – TeodorKolev
'this.state.responseCode'を意味しないのですか? – azium