qq_41333482
栗条米
2019-05-10 00:39

SpringMVC 能用表单提交查询条件 可以获得返回的值 并显示 ,但是用Ajax就不行了 ,为什么??

  • tomcat
  • json
  • java-ee
  • ajax
  • eclipse
  1. SpringMVC 能用表单提交查询条件 可以获得返回的值 并显示 ,但是用Ajax就不行了 ,为什么??
# 后台
@ResponseBody
    @RequestMapping(value = "/getstockprice")
    public ModelAndView selectStockPriceByID() {
        ModelAndView mv = this.getModelAndView();
        PageData pd = new PageData();
        boolean result = false;
        double stockPrice = 0;
        try {
            pd = this.getPageData();
            String stockNum = (String) pd.get("stockNum");
            stockPrice = (double) this.lxwstockexchangefacade.selectStockPriceByID(stockNum).get("StockPrice");
            result=true;
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
        }
        mv.addObject("result", result);
        mv.addObject("stockPrice", stockPrice);
        mv.setViewName("lxw/ExchangeDistrict");
        return mv;
    }

# Ajax
<script type="text/javascript">
        $(function(){
            alert("查询信息");
            var para ={userName:'lxl',stockNum:'000725'};
            var url = root + "/lxwempAjax/lxwOptionalStock";
            $.ajax({
                type:"POST",
                url:url,
                data:para,
                datatype:'json',
                success:function(result){
                    alert('提交成功'+para.stockNum+para.userName);
                },
                error:function(result){
                    alert('提交失败'+para.stockNum+para.userName);
                }
            });
            alert('${res.get(0).get("StockName")}');
            alert("执行完成");
        })

        </script>

# ```表单

![图片说明](https://img-ask.csdn.net/upload/201905/10/1557420188_781229.png)


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答