Created
April 18, 2017 12:41
-
-
Save anonymous/97fe7fb3cdd1b11978274d99d8606a2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component, PropTypes} from 'react'; | |
import axios from 'axios'; | |
let serialize = require('form-serialize'); | |
class NewDistrict extends Component { | |
addDistrict(event) | |
{ | |
let form = document.querySelector('#addFormDistrict'); | |
let obj = serialize(form, { hash: true }); | |
let result = JSON.stringify(obj); | |
console.log(result); | |
axios.post('http://46.236.137.153/district', { | |
method: 'POST', | |
responseType: 'json', | |
requestType: 'json', | |
headers: {'Content-Type' : 'application/json; charset=UTF-8'}, | |
data: result, | |
}) | |
.then(function () { | |
console.log('Yes.'); | |
}) | |
.catch(function (error) { | |
console.log(error); | |
console.log('Nope'); | |
}); | |
} | |
render(){ | |
return( | |
<form id="addFormDistrict" className="districtForm"> | |
<div className="alignDistrict"> | |
<div className="col-md-3"><input id="inputDistrict" type="text" name="name" placeholder="Введите новый район"/></div> | |
<div className="col-md-3"><button type="submit" id="addDistrict" onClick={this.addDistrict}>Добавить</button></div> | |
</div> | |
</form> | |
) | |
} | |
} | |
export default NewDistrict; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment