springboot前端向后端请求返回html语句

后端接口代码

   @PostMapping("/service/confirmPay")
   @ResponseBody
   public GlobalResponse confirmPay(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        //调用方法
        String html = createHtml(payUrl, httpMap);
        return GlobalResponse.success(html);
   }


	public static String createHtml(String action, Map<String, String> paramMap) {
		StringBuilder html = new StringBuilder();		
		html.append("<form id=\"submitForm\" name=\"submitForm\" action=\"").append(action).append("\" method=\"post\">\n");
		for (String key : paramMap.keySet()) {
			html.append("<input type=\"hidden\" name=\"" + key + "\"  value='" + paramMap.get(key) + "'>");
		}
		html.append("</form>\n");
		return html.toString();
	}

前端页面代码(js)

$.post(contextPath + '/service/confirmPay', param , function (res) {
			if(res.success){
				$("#payform").html(res.data);//获取后台返回的页面代码
			}else{
				layer.msg(res.alertMsg, {
	                time: 1600,
	                offset: ['40%']
	            });
			}
        })
posted @ 2021-08-04 15:47  初出茅庐小菜鸡  阅读(1633)  评论(0编辑  收藏  举报