前端页面展示JSON格式化的字符串

基于jquery.jsonview组件

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="../dist/jquery.js"></script>

<link  rel="stylesheet" href="../dist/jquery.jsonview.css">

<script src="../dist/jquery.jsonview.js"></script>

<title>User proto json</title>

</head>

<body>

<label>userId:<input id="userId" value=""></label>

<input type="submit" value="OK" onclick="doAjax()">

<br>

<label>结果:<br></label> <div id="res"></div>

</body>

<script>

function doAjax() {

var para = {

userId : $("#userId").val()

};

$.ajax({

type : "POST",

url : "id/dddd",

data : JSON.stringify(para),

contentType : "application/json",

dataType : "json",

success : function(data) {

$("#res").JSONView(JSON.stringify(data));

}

});

}

</script>

</html>

你可能感兴趣的:(前端页面展示JSON格式化的字符串)