Jeremy
Jeremy

Reputation: 5435

Spring MVC with ajax -- required long parameter 'id' is not present

Note that this question is different from #19619088 because I am trying to pass plain text.

Here is Java code:

public @ResponseBody
String decertifyAll(
    @RequestParam(value="reason",required=false) String reason,
    @RequestParam("id") long id,
    final HttpServletRequest request) {
...

Here is my ajax:

$.ajax({
    url: '/dothing',
    data: {
        id: id,
        reason: reason
    },
    processData: false,
    contentType: false,
    dataType: 'text',
    type: 'POST',
  }).done(saveDone)
    .fail(saveFail)
    ;

In firebug, this is captured:

Source
{"id":"1492811","reason":"text"}

But, I still get the error:

 Required long parameter 'id' is not present

The weird thing is, this actually worked fine and then suddenly stopped working. I have no idea why.

My question is: What do I need to change so that I can pass this data correctly, and why is it failing to find the data that I am passing and that is making it into the post request?

I don't want to wrap this all up in some other object, but I will if needed.

Upvotes: 0

Views: 5570

Answers (1)

Jeremy
Jeremy

Reputation: 5435

This was solved by removing some of the optional parameters that I have in my AJAX call:

$.ajax({
    url: '/dothing',
    data: {
        id: id,
        reason: reason
    },
    type: 'POST',
  }).done(saveDone)
    .fail(saveFail)
    ;

I'm guessing that beerbajay's comment was correct that processData:false was the cause.

Upvotes: 2

Related Questions