-1

I found this link when searching for a solution. It suggests a bugfix in version 1.4.x. Thats a realy old version and i havent been fixed yet?

$.ajax ignoring data param for DELETE requests

The code below works perfectly find on a GET taking exactly the same request parameters. How I call the DELETE method?

    var data = {
            accessToken : accessToken
        }



        $.ajax({
            type : 'DELETE',
            url : "/user/" + userId,
            cache : false,
            data : data,
            success : function(profile) {
                $("#account-delete .response-container").html(JSON.stringify(profile, null, 2));
                $("#account-delete .request-container").html("/user/?" + $.param(data));
            }, 
            error : function(jqXHR, textStatus, errorThrown) {
                $("#account-delete .error-container").html(textStatus +" - " +  errorThrown);

            }

        });
Community
  • 1
  • 1
pethel
  • 5,397
  • 12
  • 55
  • 86

3 Answers3

0

did you check out this other SO question Here? This may be your problem:

Just a note, if you're using an IIS webserver and the jquery PUT or DELETE requests are returning 404 errors, you will need to enable these verbs in IIS. I've found this to be a good resource:

http://geekswithblogs.net/michelotti/archive/2011/05/28/resolve-404-in-iis-express-for-put-and-delete-verbs.aspx

Community
  • 1
  • 1
Scott Selby
  • 9,420
  • 12
  • 57
  • 96
0

you probably shouldn't be using DELETE because some browsers won't support it according to the jQuery documentation.

Maybe this answer will help as an alternative.

Community
  • 1
  • 1
VVV
  • 7,563
  • 3
  • 34
  • 55
0

Ok this soultion works.

Add this filter in web.xml

<filter>
    <filter-name>hiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</filter>

Call the controller with POST providing _method: 'DELETE' in data.

  $.ajax({  
        url: "/application/form",
        type: 'POST',  
        data: { 
            _method: 'DELETE',
            param : "param"

        },  
        success: function (res) {  
            console.log("success");
        } , 
        error: function (res) {  
            alert(res);
        } 
    });
pethel
  • 5,397
  • 12
  • 55
  • 86