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%']
	            });
			}
        })


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM