I implemented a small REST API using JAX-RS (Jersey 2.0), and I use AJAX to call the API, GET and POST, but when I get a call to any PUT or DELETE methods, all I get is the following error message:
Failed to load resource: server responded with status 403 (Forbidden)
Here is an example of the DELETE method in Java:
@Path("/deleteSomething") @DELETE @Consumes("application/json") public void delete(String json) throws ParseException { JSONParser parser = new JSONParser(); Object obj = parser.parse( json ); JSONObject object=(JSONObject)obj; String id = (String) object.get("id"); System.out.println("ID : " + id);
And here is the Javascript call using AJAX:
function deleteSomethingAjax() { $.ajax({ url: API_URI + "/deleteSomething", //API_URI is the API uri contentType : 'application/json', data: idToJSON(), // this function just returns a JSON obj {"id":"myID"} type: 'DELETE', success : function(data, textStatus, jqXHR) { alert( "Fine!" ); }, error : function(jqXHR, data, textStatus, errorThrown) { alert('WOOPS, something wrent wrong...'); } }); }
Any help would be greatly appreciated !! Thanks!
source share