Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let UserName = React.createClass({
- getInitialState: function(){
- return ({
- listQuestions:[],
- username: ""
- })
- },
- componentDidMount: function(event){
- let formData = new FormData(event),
- username = formData.get("username");
- if(!username){
- return false;
- }
- fetch("/ajax/get-userdata.php",{
- credentials:'same-origin',
- method:"POST",
- body:formData
- }).then(response=>{
- if(response.status>=200 && response.status<300){
- return response.json();
- }else{
- Promise.reject();
- }
- }).then(json=>{
- this.setState({
- username:json.username
- });
- }).catch(e=>{
- alert(e)
- });
- },
- render: function(){
- return (
- <div>
- <IndexForm onSubmit={this.componentDidMount} />
- <div>
- <h2>Список вопросов пользователя {this.state.username}</h2>
- </div>
- <allQuestions />
- <div style={{marginTop:20}}>
- <form method="post">
- <textarea cols="100" rows="10" placeholder="Новый вопрос" name="newQuestion"></textarea>
- <br />
- <input type="submit" value="Задать вопрос" />
- </form>
- </div>
- </div>
- )
Add Comment
Please, Sign In to add comment