SHARE
TWEET

Untitled

a guest May 25th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2.  
  3. class Form extends Component {
  4.     constructor(props) {
  5.         super(props)
  6.         this.state = {}
  7.     }
  8.     submitForm = (event) => {
  9.         event.preventDefault()
  10.         let oneData = document.getElementById('one')
  11.         let twoData = document.getElementById('two')
  12.         let data = {
  13.             "one": oneData,
  14.             "two": twoData
  15.         }
  16.         const url = "127.0.0.1:5000"
  17.         fetch(url, {
  18.             method: "POST",
  19.             headers: {
  20.                 "Content-Type": "application/json"
  21.             },
  22.             body: JSON.stringify(data)
  23.         }).then(
  24.             response => {
  25.                 response.json()
  26.             }
  27.         ).then(
  28.             data => {
  29.                 console.log(data)
  30.             }
  31.         )
  32.     }
  33.     render() {
  34.         return (
  35.             <form>
  36.                 <input type="text" placeholder="two" id="one"/>
  37.                 <input type="text" placeholder="one" id="two"/>
  38.                 <input type="submit" onClick={this.submitForm()}/>
  39.             </form>
  40.         )
  41.     }
  42. }
  43.  
  44. export default Form;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top