简体   繁体   English

客户端发送的请求在spring mvc,ajax中在语法上不正确

[英]The request sent by the client was syntactically incorrect in spring mvc, ajax

Below is the ajax call to my controller 下面是对我的控制器的ajax调用

$('#submitButton').on('click', function() {
            var expenseDetailsListVO = {};
            expenseDetailsListVO = getData();
            console.log(expenseDetailsListVO);
            var data = JSON.stringify(expenseDetailsListVO);
            console.log(data);
            $.ajax({
                url : "${pageContext.request.contextPath}/saveExpenses",
                data : data,
                method : 'POST',
                contentType : "application/json",
                success : function(data) {

                },
                error : function(data) {

                }
            });
        });

This is my controller 这是我的控制器

@RequestMapping (value = "/saveExpenses", method=RequestMethod.POST)
    public String saveExpenses (@RequestBody(required=false) ExpenseDetailsListVO expenseDetailsListVO, Model model) {


        //System.out.println("User Id is........ "+userId);
        System.out.println(expenseDetailsListVO);
        ExpenseDetailsList expenseDetailsList = MapperUtil.convertExpenseListVOToDO(expenseDetailsListVO);

        //expenseServiceManagement.addExpense(expenseDetailsList);

        return "addExpense";
    }

And below are my java classes 以下是我的Java类

public class ExpenseDetailsListVO {


    private List<ExpenseDetailsVO> expenseDetailsVOs = LazyList.decorate(
            new ArrayList<ExpenseDetailsVO>(),
            FactoryUtils.instantiateFactory(ExpenseDetailsVO.class));

public ExpenseDetailsListVO (){}

    public List<ExpenseDetailsVO> getExpenseDetailsVOs() {
        return expenseDetailsVOs;
    }

    public void setExpenseDetailsVOs(List<ExpenseDetailsVO> expenseDetailsVOs) {
        this.expenseDetailsVOs = expenseDetailsVOs;
    }

    @Override
    public String toString() {
        return "ExpenseDetailsListVO [expenseDetailsVOs=" + expenseDetailsVOs
                + "]";
    }

}



   public class ExpenseDetailsVO {

        /*private int expenseId;*/

        private String itemDescription;

        private double amount;

        private Date expenseDate;

public ExpenseDetailsVO (){}
        /*public int getExpenseId() {
            return expenseId;
        }

        public void setExpenseId(int expenseId) {
            this.expenseId = expenseId;
        }*/

        public String getItemDescription() {
            return itemDescription;
        }

        public void setItemDescription(String itemDescription) {
            this.itemDescription = itemDescription;
        }

        public double getAmount() {
            return amount;
        }

        public void setAmount(double amount) {
            this.amount = amount;
        }

        public Date getExpenseDate() {
            return expenseDate;
        }

        public void setExpenseDate(Date expenseDate) {
            this.expenseDate = expenseDate;
        }

        @Override
        public String toString() {
            return "ExpenseDetailsVO [itemDescription=" + itemDescription
                    + ", amount=" + amount + ", expenseDate=" + expenseDate + "]";
        }

    }

Previously it was working but something I changed which I can't recall and now am getting error in browser console as the request sent by the client was syntactically incorrect 以前它可以正常工作,但是我进行了一些更改,使我不记得了,现在由于客户端发送的请求在语法上不正确,导致浏览器控制台出现错误

Guys please let me know what is the issue... 伙计们,请让我知道这是什么问题...

There was a very small mistake because of which it was showing that error... So I just needed to do small change, below is the jquery 有一个很小的错误,因为它显示了该错误...所以我只需要做一些小改变,下面是jQuery

$('#submitButton').on('click', function() {
            var expenseDetailsListVO = {};
            expenseDetailsListVO = getData();
            console.log(expenseDetailsListVO);
            var data = JSON.stringify(expenseDetailsListVO);
            console.log(data);
            $.ajax({
                url : "${pageContext.request.contextPath}/saveExpenses",
                data : data,
                method : 'POST',
                contentType : "application/json",
                success : function(data) {

                },
                error : function(data) {

                }
            });
        });

My controller was expecting an object which will be having array of object but from client side it was sending arrays, so that array needed to be wrapped inside an object which I did and its working :) 我的控制器期待一个对象,该对象将具有对象数组,但从客户端它正在发送数组,因此该数组需要包装在一个我做过的对象中并起作用:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spring mvc - 客户端发送的请求在语法上是不正确的 - spring mvc - The request sent by the client was syntactically incorrect Spring MVC文件上传-客户端发送的请求在语法上不正确 - Spring MVC File Upload - The request sent by the client was syntactically incorrect Spring MVC-上传文件显示客户端发送的请求在语法上不正确 - Spring MVC - upload file shows The request sent by the client was syntactically incorrect 使用Spring MVC进行CRUD时出现错误“客户端发送的请求在语法上不正确” - Error “The request sent by the client was syntactically incorrect” when CRUD with Spring MVC Spring MVC:上传文件时“客户端发送的请求在语法上不正确”? - Spring MVC : “The request sent by the client was syntactically incorrect” when uploading a file? Spring MVC:错误400客户端发送的请求在语法上是不正确的 - Spring MVC: Error 400 The request sent by the client was syntactically incorrect Spring形式:客户端发送的请求在语法上不正确() - Spring form : The request sent by the client was syntactically incorrect () Spring:客户端发送的请求在语法上是不正确的() - Spring: The request sent by the client was syntactically incorrect () SPRING框架:客户端发送的请求在语法上不正确 - SPRING framework: The request sent by the client was syntactically incorrect 客户端发送的请求在语法上不正确 - The request sent by the client was syntactically incorrect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM