简体   繁体   中英

bad request 400 error while sending request to RestControler Spring MVC

I am getting bad request 400 error while sending request with parameters to controler I have checked whole sysntax but I did not wind any mistake, please look at my code whats wrong there?

var url = contextPath+"/billingControler/getOrdersByResWiseTables";
$.ajax({    
    url      : url,
    data     : "&resID="+$("#rsId").text()+"&tblid="+tableId,  
    type     : "get",     
    dataType : "json" ,
    contentType : 'application/json; charset=utf-8',
    success  : function(response) {             
        console.log(response); 
    } 
}); 

error :

jquery-3.3.1.min.js?_=1520931033076:2 GET http://localhost:8088/smartpos/billingControler/getOrdersByResWiseTables?&resID=11&tblid=3 400 (Bad Request)

please check my java code

@RequestMapping(value="/getOrdersByResWiseTables", method=RequestMethod.GET,   produces="application/json")

public List<OrderBans> getOrdersByResWiseTables(@RequestParam("resId") String resId,@RequestParam("tblid") String tableid) {   
    String result="";
    logger.debug("Started adding order");

    RestypeIDao pdo = new RestypeIDaoImp();  

    List<OrderBans> orderList = pdo.getOrdersResWIseTbles(resId, tableid);

    System.out.println(orderList);  
    logger.debug("end adding order");
    return orderList;

} 

You have extra & in your URL.

Also, you're using data attribute wrong, it should be an object. Try this:

var url = contextPath+"/billingControler/getOrdersByResWiseTables";
$.ajax({
    url : url,
    data: {
        "resID": $("#rsId").text(),
        "tblid": tableId
    },
    dataType:"json",
    contentType:'application/json; charset=utf-8',
    success:function(response) {
        console.log(response);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM