简单ajax

前台:

<script>

$(function(){

    var projectId = $V("projectId");

    $.ajax({

        url : '../../../ZdyPmProjectInfo.project/qrCode?projectId='+projectId,

        dataType : 'json',

        type : 'html',

        success : function(data) {

            $('#qrCodeId').html("<img src='"+data.qrCodeUrl+"' />");

        }

    })

})

</script>

</head>

<body class="z-body-list">

<input type="hidden" id="projectId" value="${projectId}" />

    <div id="qrCodeId" />

</body>

</html>

</script>

 

后台:

 @Alias("project/qrCode")

    public void qrCode(ZAction za)

        throws WriterException, IOException {

        JSONObject json = new JSONObject();

        String projectId = $V("projectId");

        // 移动端打开的链接地址

        String surveyUrl = ConstantsAllUtils.SERVER_URL_165 + "&projectId=" + projectId;

        int width = 300;

        int height = 300;

        // 二维码的图片格式

        String format = "gif";

        Hashtable hints = new Hashtable();

        // 内容所使用编码

        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");

        BitMatrix bitMatrix = new MultiFormatWriter().encode(surveyUrl, BarcodeFormat.QR_CODE,

            width, height, hints);

        // wwwroot_release/.../ upload/qrCode

        String filePath = SiteUtil.getSiteRoot(SiteBL.getCurrentSite()) + QRCODE_URL;

        // 二维码文件目录

        File outputFile = new File(filePath + projectId + "_qrcode." + format);

        if (!outputFile.exists()) {

            FileUtil.mkdir(filePath);

        }

        // 生成二维码图片

        QrCodeUtil.writeToFile(bitMatrix, format, outputFile);

        json.put("qrCodeUrl", SiteUtil.getPreviewPrefix(SiteBL.getCurrentSite()) + QRCODE_URL

                              + projectId + "_qrcode." + format);

        za.writeJS(json.toJSONString());

    }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值