2

I am trying to send object's array to Spring controller via jQuery AJAX. Here is the javascript code:

var data = new Array();
            $.each(products, function (i) {
                var temp = {};
                temp.orpid = products[i].orpid;
                temp.orpah = $('#orpah' + products[i].orpid).is(':checked');
                temp.orpad = $('#orpad' + products[i].orpid).val();
                data.push(temp);
            });
            $.postJSON(url + 'save',
                    data,
                    function(response) {
                        if (response.isAuthenticated && response.isAuthorized) {
                            if (response.hasErrors) {
                                $('#routeForm').setErrors(response.errors);
                                hideWait();
                            }
                        }
                        else
                            redirectToLogin();
                    });

Here are the params that are sent to the server:

[{"orpid":10,"orpah":false,"orpad":""},{"orpid":11,"orpah":false,"orpad":""}]

The controller's method has following definition:

@RequestMapping(value = "/save", method = RequestMethod.POST, headers = BaseController.AJAX_HEADER)
public ModelAndView save(@RequestBody HandlingOrderProductActionForm form, HttpServletResponse response) {...}

where HandlingOrderProductActionForm is:

public class HandlingOrderProductActionForm extends BaseForm {  
public class ActionForm {
    private Boolean orpah;
    private String orpad;
    private Long orpid;

    public ActionForm() { }

    public void setOrpah(Boolean orpah) {
        this.orpah = orpah;
    }

    public Boolean getOrpah() {
        return orpah;
    }

    public void setOrpad(String orpad) {
        this.orpad = orpad;
    }

    public String getOrpad() {
        return orpad;
    }

    public void setOrpid(Long orpid) {
        this.orpid = orpid;
    }

    public Long getOrpid() {
        return orpid;
    }
}

private List<ActionForm> actions;

/**
 * 
 */
public HandlingOrderProductActionForm() {
    super();
}

public void setActions(List<ActionForm> actions) {
    this.actions = actions;
}

public List<ActionForm> getActions() {
    return actions;
} }

The problem is, that the server returns an 415 error:

The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().

Any ideas? Thank you

1 Answer 1

1

THe problem is solved - just move the ActionForm to separate class!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.