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