Ajax发送请求后,将返回页面以弹出层(layer)的形式展现

需求:
点击前台界面的按钮,查询合同详细信息,要求用layer弹出层

1、前台jsp页面

<a href="#">
<span class="clickMe" title="明细信息查询">span>
a>
<script type="text/javascript">
$(document).on("click",".clickMe",function(){
    var id = $("#id").val();
    var url = '${pageContext.request.contextPath}/contract/queryContract.jhtml?id='+id;
    $post(url,function(result){ //通过Ajax发送请求到后台
        layer.open({
            type : 1,   //获取页面层信息
            title : '合同信息',
            btn : ['取消','确定'],
            skin : "layui-layer-molv",
            border : [1],
            area : ['86%','90%'],
            content : $(result).find("#contractText").html()    //把result转为jQuery对象
        });
    });
});
script>

2、Controller层

@Controller
@requestMapping"/contract"public class contract{
    @requestMapping"/queryContract"public String queryContract(Model model,HttpServletRequest request){
        String id = request.getParameter("id");
        ContractService service = new ContractServiceImpl();
        Contract c = service.queryContractById(id);
        model.addAttribute("Contract ",c);
        retrun "/contractInfo";  //返回contractInfo.jsp页面
    }
}

3、contractInfo.jsp

"contractText"> ${Contract.id} ${Contract.name} ... ...

你可能感兴趣的:(Ajax发送请求后,将返回页面以弹出层(layer)的形式展现)