I tried to delete a record from database by calling a Rest service passing the Table id through ajax.
The function wired to click of delete button:
[$("#deleteRecord").click(function(){
$.ajax({
type:"DELETE",
datatype:"text",
url:"http:/localhost:8080/bookProject/book/bookAccess/deleteBook?bookNo="+$("#bookNo").val(),//URL of local rest service bookNo is the Id of input
success:function(data)
{
alert("success");
},
error:function(e)
{
alert("Ajax error");
console.log(e);
}
});
});][1]
The server side code is as follows:
@DELETE
@Path("/deleteBook")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public String deleteBook(@QueryParam("bookNo")String bookNumber)
{
String message="Deleted Succesfully";
// jdbc to delete from database
try
{
MysqlDataSource ds=new MysqlDataSource();
ds.setServerName("localhost");
ds.setPort(3306);
ds.setUser("Sachu");
ds.setPassword("Password01");
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
stmt.execute("delete from customer.booktable where bookNo="+bookNumber);
conn.close();
}
catch(SQLException e)
{
message ="Error in deleting from the database";
}
return message;
}
// But when I click the delete button, the console displays a 404(Resource Not Found) Tomcat 6 error. I am able to do the operations PUT,POST and GET. Also when accessing from HTML document(not through localhost), DELETE does not throw an error. But when accessing through localhost(same origin),Tomcat throws an error. Can someone please let me know what the source of error is.Thanks in advance. Error Image