Guest User

Untitled

a guest
Jan 21st, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. let UserName = React.createClass({
  2. getInitialState: function(){
  3. return ({
  4. listQuestions:[],
  5. username: ""
  6. })
  7. },
  8.  
  9. componentDidMount: function(event){
  10.  
  11. let formData = new FormData(event),
  12. username = formData.get("username");
  13.  
  14. if(!username){
  15. return false;
  16. }
  17. fetch("/ajax/get-userdata.php",{
  18. credentials:'same-origin',
  19. method:"POST",
  20. body:formData
  21. }).then(response=>{
  22. if(response.status>=200 && response.status<300){
  23. return response.json();
  24. }else{
  25. Promise.reject();
  26. }
  27. }).then(json=>{
  28. this.setState({
  29. username:json.username
  30. });
  31. }).catch(e=>{
  32. alert(e)
  33. });
  34. },
  35. render: function(){
  36. return (
  37. <div>
  38. <IndexForm onSubmit={this.componentDidMount} />
  39. <div>
  40. <h2>Список вопросов пользователя {this.state.username}</h2>
  41. </div>
  42. <allQuestions />
  43. <div style={{marginTop:20}}>
  44. <form method="post">
  45. <textarea cols="100" rows="10" placeholder="Новый вопрос" name="newQuestion"></textarea>
  46. <br />
  47. <input type="submit" value="Задать вопрос" />
  48. </form>
  49. </div>
  50. </div>
  51. )
Add Comment
Please, Sign In to add comment