Ошибка 405 при попытке УДАЛИТЬ запрос AJAX - Java - PullRequest
0 голосов
/ 07 июня 2018

Я пытаюсь отправить запрос на удаление в мой java-сервис с помощью ajax-запроса от моей клиентской стороны.Но когда я смотрю в сети на консоли, он выдает следующее сообщение:

Request URL: http://localhost:8888/api.html/delete/AF
Request Method: DELETE
Status Code: 405 
Remote Address: [::1]:8888
Referrer Policy: no-referrer-when-downgrade

Мой код Java выглядит так:

@Path("/api.html")
public class WorldService {
     private CountryPostgresDaoImpl CountryPostgresDao = new CountryPostgresDaoImpl();

@Path("/delete/{code}")
@DELETE
@Produces("application/json")
public Response deleteCountry(@PathParam("code") String code) throws SQLException {
    Country country = getCountryByCode(code);
    if(!CountryPostgresDao.Delete(country)) {
        return Response.status(404).build();
    }
    return Response.ok().build();

}

А клиентская сторона выглядит так:

    $("body").on('click', '#delete', function(){
         var trid = $(this).closest('tr').attr('id');
         console.log(trid);
         $.ajax({
             url: '/api.html/delete/' + trid,
             type: 'DELETE',
             success: function(response) {
                 console.log(response);
             }
         });
     });

1 Ответ

0 голосов
/ 07 июня 2018

Удалить начальную косую черту, как показано в следующем фрагменте

@Path("delete/{code}")
@DELETE
...