【发布时间】:2018-12-03 00:03:50
【问题描述】:
到目前为止,我已通过Home.js 成功地将信息插入数据库(SQL、phpMyAdmin),但问题是每次用户输入信息并点击submit,它都会被重定向到我的demo.php文件(未提供)而不是 Next.js。
也就是说,我怎样才能使用户信息成功进入数据库并进入下一页? (Next.js)?
我做错了什么,我该如何解决?
这里是Home.js:
import React, { Component } from 'react';
import Next from '../Home/Next';
class Home extends Component {
constructor(props) {
super(props);
this.state = {
show: false
};
this.getPHP = this.getPHP.bind(this);
this.goNext = this.goNext.bind(this);
}
getPHP() {
fetch(`http://localhost/demo_react/api/demo.php`, {
method: 'POST'
}).then(res => res.json())
.then(response => {
console.log('response');
console.log(response);
});
}
goNext() {
this.setState({show: true});
}
render() {
const next = this.state.show;
if(next) {
return <Next/>;
}
return (
<div>
<br/>
<form className="form-control" action="http://localhost/demo_react/api/demo.php" method={"POST"} encType="multipart/form-data">
<input type="text" name="username"/>
<input type="text" name="password"/>
<input type="submit" value="submit" onClick={this.getPHP & this.goNext} name={"submit"}/>
</form>
</div>
);
}
}
export default Home;
这里是Next.js:
import React, { Component } from 'react';
class Next extends Component {
render() {
return(
<h1>made it</h1>
);
}
}
export default Next;
【问题讨论】:
标签: javascript php reactjs debugging