如何使用react将Rest API数据服务从一个组件发布到另一个组件?

时间:2017-05-29 04:42:25

标签: jquery ajax api reactjs post

componentDidMount() {
   $.ajax({
    type: 'POST',
    url: 'http://localhost:8080/UIServices/rest/dataService/postDataConnection?userName=SIVASO',
    data: {
    dataConnectionName: this.state.dataConnectionName,
    dataConnectionType: this.state.dataConnectionType,
    databaseHost: this.state.databaseHost,
    dataConnectionSid: this.state.dataConnectionSid,
  dataConnectionUsername: this.state.dataConnectionUsername,
  dataConnectionPassword: this.state.dataConnectionPassword,
  description: this.state.description,
  connectionMethod: this.state.connectionMethod,
  databasePort: this.state.databasePort,
  jdbcDriver: this.state.jdbcDriver
  }
  })
  .done(function(data) {
    self.clearForm()
  })
  .fail(function(jqXhr) {
    console.log('failed to save');
  });

}

handleSubmit(e){
var self

  e.preventDefault();
  self = this

  console.log(this.state);

  var data = {
    dataConnectionName: this.state.dataConnectionName,
    dataConnectionType: this.state.dataConnectionType,
    databaseHost: this.state.databaseHost,
    dataConnectionSid: this.state.dataConnectionSid,
  dataConnectionUsername: this.state.dataConnectionUsername,
  dataConnectionPassword: this.state.dataConnectionPassword,
  description: this.state.description,
  connectionMethod: this.state.connectionMethod,
  databasePort: this.state.databasePort,
  jdbcDriver: this.state.jdbcDriver
  }
  }

clearForm() {
  this.setState({
    dataConnectionName: "",
    dataConnectionType: "",
    databaseHost: "",
    dataConnectionSid: "",
  dataConnectionUsername: "",
  dataConnectionPassword: "",
  description: "",
  connectionMethod: "",
  databasePort: "",
  jdbcDriver: ""
  });
}

我无法在使用帖子休息服务连接后将数据发布到用户界面,任何人都可以帮助我,我在最近2天无法找到任何解决方案。提前谢谢。

保存数据后,我将详细填写所有连接,应将其存储在卡片格式的所有字段的其他组件中。

发布后我能够在检查中获得响应但不在get url中发布数据

0 个答案:

没有答案