如何在react.js中工作

时间:2015-09-23 15:06:51

标签: javascript jquery reactjs mithril.js

我正在开发一个项目,我想在从Ajax成功登录后加载另一个组件或模块,我们可以做反应

$.ajax({
  url: url_root+"/auth/token",
  dataType: 'json',
  type: method.post,
  data: data,
  success: function(data) {
    console.log(data);
    // redirect... to another page
  }.bind(this),
  error: function(xhr, status, err) {
    console.error(status);
    this.setState({username : true, password :true});
  }.bind(this)
});

2 个答案:

答案 0 :(得分:1)

你想为此使用ReactRouter。 https://github.com/rackt/react-router

答案 1 :(得分:0)

你可以在这里使用诺言。看看axios https://github.com/mzabriskie/axios。您可以拨打电话,但会返回承诺,以便您可以执行某些操作(例如......)

axios.get('/user?ID=12345')
  .then(function (response) {

    this.setState({...)} /// or if you are using Flux (from store emit event to update your view or so on...)

  })
  .catch(function (response) {
    console.log(...)//throw new Error.....
  });

它应该像使用axios一样简单。其他可能性见http://www.sitepoint.com/comparison-javascript-http-libraries/

希望这很有用