【发布时间】:2017-05-19 09:01:50
【问题描述】:
这是我的反应表单...我需要获取输入的值,但是每当我检查网络时,以下是未定义的,请帮我添加数据但为空
<td>Name</td>
<td>
<input type="text"
value={this.props.Employee_Name}
onChange={(e) => this.handleChange(e)}
/>
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text"
name="Address"
value={this.props.Address}/>
</td>
</tr>
<tr>
<td>Department</td>
<td>
<input type="text"
value={this.props.Department}
/>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<input type="submit" className="btn btn-info" onClick = { this.handleSubmit.bind(this, this.Employee_Name ,this.Address ,this.Department)} value =" Add Employee"/>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
这部分是我为 post 方法获取 api 的代码,因此它将在 api 上发送数据
handleSubmit( name, address,department){
debugger
const data = {
'Employee_Name': name,
'Address': address,
'Department': department
}
return fetch('http://localhost:5118/api/employeedetails/PostEmployeeDetail?', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(function(response) {
}).catch(function(err) {
// Error :(
});
}
【问题讨论】:
-
控制台有什么错误吗?
-
未捕获的类型错误:将循环结构转换为 JSON
标签: javascript asp.net api reactjs web