嗨我有问题为什么我的代码不能处理任何其他方法除了我已经尝试在api上随机添加东西但是它一直在改变状态代码405或404或现在500我不知道什么是错的但我很漂亮确定它在api上请帮助
这是我的代码
componentDidMount() {
fetch('http://localhost:5118/api/employeedetails/getemployeedetails/')
.then((response) => {
return response.json()})
.then((json) => {
this.setState({jsonReturnedValue : json});
});
}
这是我的删除代码,但它不起作用(它表示获取错误)
deleteEmployee(id) {
jQuery.support.cors = true;
debugger
fetch ('http://localhost:5118/api/employeedetails/DeleteEmployeeDetail/'+ id,
{ method: 'DELETE',
credentials: 'same-origin'})
.then(
res => {
this.setState({jsonReturnedValue : json})
var employee = [...this.state.employee];
var idx = employee.findIndex(item => item.Employee_ID === id);
employee.splice(idx, 1);
this.setState({employee})
}
)
.catch( err => console.error(err))
}
这是删除按钮的代码
<td><center><button className ="btn btn-danger" onClick={this.deleteEmployee.bind(this, d.Employee_ID)}>Delete</button></center></td>
这是我的api web config代码
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ReactJsx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" path="*.jsx" type="React.Web.JsxHandlerFactory, React.Web" preCondition="integratedMode" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>