$.ajax({
type : "post",
async : false, // 同步执行
url : "virtualProduct.html",
data : "1=1",
success : function(result) {
if (result) {
var dataObj = eval("("+result+")");//后台返回数据一定转化成对象,不能拿不到值
<span style="white-space:pre"> </span>//此处开始开始用字符串形式json格式化,和在线json格式化一样,json字符串是<span style="font-family: Arial, Helvetica, sans-serif;">endResult</span>
<span style="white-space:pre"> js_source = endResult.replace(/^\s+/, '');
tabchar = ' ';
var start=js_beautify(js_source, 8, tabchar);
$("#content").val("虚拟设备上报数据:"+"\r\n"+start);</span>//得到格式化好了的字符串start放在id为content的value下
<span style="white-space:pre"> </span>下面是生成二维码
$("#code").qrcode({
render: "table", //table方式
width: 120, //宽度
height:120, //高度
text: <span style="font-family: Arial, Helvetica, sans-serif;">result</span>//任意内容生成二维码
});
}
},
});
格式化需要引入
<SCRIPT src="images/base2-p.js" type=text/javascript></SCRIPT>
<SCRIPT src="images/packer-p.js" type=text/javascript></SCRIPT>
<SCRIPT src="images/beautify.js" type=text/javascript></SCRIPT><SCRIPT src="images/beautify-tests.js" type=text/javascript></SCRIPT>
<SCRIPT src="images/HTML-Beautify.js" type=text/javascript> </SCRIPT>
二维码需要引入
<script type="text/javascript" src="<%=basePath%>static/lib/jquery.qrcode.min.js"></script>