1

import React, { Component } from 'react';
 import { Link } from 'react-router'
import { Dropdown, DropdownMenu, DropdownItem, Progress } from 'reactstrap';

class Modals extends Component {
constructor(){
super();
  fetch("http://api-env.bt2qjip33m.ap-south-1.elasticbeanstalk.com/api/v1/beacons" ,
 {
  method: 'post',
 headers: {
'Content-Type': 'application/json',
'Authorization' : 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1OGMyOTdiO  WQzZWM4NjY4MDMwNDBlNjgiLCJlbWFpbCI6ImtrQGxpdGlmZXIuY29tIiwiZmlyc3ROYW1lIjoiS2lzaGxheSIsImxhc3ROYW1lIjoiS2lzaG9yZSIsImlhdCI6MTQ4OTE0NzgzM30.nHW5w3SSov8ySziblmw2VNlGI3CsZFR-v41Jeg9uBVs'
},
body: JSON.stringify({
name: "beacon name",
description: "beacon description here",
uuid: "mnvijefnv",
major: "2",
minor: "2",
manufacturer: "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24",
beaconType: "type1",
location: "main gate1",
floor: "",
zone: "58c29c06d3ec866803040e6e"
})
}).then(function(response){
if(response.ok) {
  console.log(response)
return response;
}
throw new Error('Network response was not ok.');
}).then(function(data) { 
console.log(data);
})
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error);
});
  }

   render() {
   return (<div><div>
      <div className="animated fadeIn">
        <br /><div className="card" style={{ width: 57 + '%' }}>
          <div className="card-header">
             Beacon Settings
          </div>
          <div className="card-block">
            <div className="input-group mb-1">
              <span className="input-group-addon"><i className="icon-user"></i></span>
              <input type="text" className="form-control" placeholder="UUID" />
            </div>

            <div className="input-group mb-1">
              <span className="input-group-addon"><i className="fa fa-align-justify"></i></span>
              <input type="text" className="form-control" placeholder="Major Number"/>
            </div>

            <div className="input-group mb-1">
              <span className="input-group-addon"><i className="fa fa-align-justify"></i></span>
              <input type="text" className="form-control" placeholder="Minor Number"/>
            </div>

            <div className="input-group mb-1">
              <span className="input-group-addon"><i className="fa fa-align-justify"></i></span>
              <input type="text" className="form-control" placeholder="Manufacturer Number"/>
            </div><center>
            <Link to={'/components/tabs'} style={{ width: 27 + '%' }} className="nav-link btn btn-block btn-success" activeClassName="active">Save</Link>

<Link to={'/components/tabs'} style={{ width: 27 + '%' }} className="nav-link btn btn-block btn-success" activeClassName="active">Advance Settings</Link>
</center>

        </div>
      </div>
 </div></div>
  </div>
  
    
  
     )
 }
}

export default Modals;

I want to save the data to the server using POST request It had taken data from the fields by the user. The data will be sent to the server on clicking on "Save" button. Actually I searched for that but I didn't found any relevant information

5
  • You can use fetch('url', {options}).then().catch(). Take a look. You have an example here Commented Mar 9, 2017 at 12:15
  • 1
    As I understand on the save button press you want to POST the form and then navigate to another component. Am I correct. If yes, then where do you want to POST, i mean which is the api endpoint Commented Mar 9, 2017 at 16:44
  • POST /api/v1/beacons i think you are asking about that Commented Mar 10, 2017 at 7:04
  • server will be litifer.com/Beacons Commented Mar 10, 2017 at 8:05
  • stackoverflow.com/questions/42828145/… Commented Mar 16, 2017 at 8:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.