User135423268 posted
Good Day
I'm having a problem when I'm calling my PUT Method on Web API, here's my code below.
WEB API:
<HttpPut>
<Route("api/{controller}/putemployee")>
Public Sub UpdateOurEmployee(<FromBody()> ByVal EmpList as Employees)
using sqlConn as new sqlConnection(connstrEmp)
using sqlCmd as new SqlCommand("sp_UpdateEmployee",sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.AddWithValue("@EmpID",EmpList.EmpID)
sqlCmd.Parameters.AddWithValue("@FirstName",EmpList.FirstName)
sqlCmd.Parameters.AddWithValue("@MiddleName",EmpList.MiddleName)
sqlCmd.Parameters.AddWithValue("@LastName",EmpList.LastName)
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
end using
end using
End Sub
Here's my code on Jquery/Ajax
var EmpList {EmpID: objEmpID, FirstName: objFirstName, MiddleName: objMiddleName, LastName: objLastName}
$.ajax({
url: '/api/myapi/putemployee',
data: JSON.stringify(EmpList),
type: 'PUT',
contentType: 'application/json',
success: function (response) {
alert(response + ' success');
},
error: function (xhr) {
alert(xhr);
}
});
Wierd is I have no problem on my PUT in API, there is no error or on my method, the error shows during the alert of success, "response" shows "undefined",
I have solve this by removing the alert() on under success, but this is bothered me, that It may cause a problem or there some error that i don't see.
I hope you can give me advise on this.
Thanks and regards