Witam,
mam problem z wysłaniem JSONA jako obiektu. Nie pobiera mi danych z inputa tylko wysła nulla. Próbowałem już na wiele sposobów i żaden z nich nie przynosi rezultatu. Zostawiłem teraz pustego JSON.stringify. Czy ktoś mógłby mi pomóc?
class Create extends Component {
constructor() {
super();
this.state = {
ProductId: '',
FactoryId: '',
Name: '',
Description: '',
Category: '',
Availability: ''
};
}
onChange = (e) => {
const state = this.state
state[e.target.name] = e.target.value ;
this.setState(state);
}
post = () => {
fetch('/api/Products',
{
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify()
});
};
render() {
const { ProductId, FactoryId, Name, Description, Category, Availability } = this.state;
return (
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
ADD PRODUCT
</h3>
</div>
<div class="panel-body">
<h4><Link to="/fetch"><span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> Products List</Link></h4>
<form onSubmit={this.post} name="form">
<div class="form-group">
<label for="isbn">FactoryId:</label>
<input type="text" class="form-control" name="FactoryId" value={FactoryId} onChange={this.onChange} placeholder="FactoryId" required/>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
</div>
);
}
}