ASP.NET实现二维码(QRCode)的创建和读取实例(3)

}
function getQrImg()
{
    var txt_qr = escape($.trim($("#txt_qr").val()));
    var qrEncoding = $("#Encoding").val(); ;
    var Level = $("#Level").val(); ;
    var txt_ver = $("#txt_ver").val(); ;
    var txt_size = $("#txt_size").val(); ;
    $.ajax({
        type: "GET",
        data: "cmd=set&txt_qr=" + txt_qr + "&qrEncoding=" + qrEncoding + "&Level=" + Level + "&txt_ver=" + txt_ver + "&txt_size=" + txt_size,
        url: "Ashx/test.ashx",
        dataType: 'text',
        beforeSend: function (x)
        {
            x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        },
        success: function (json)
        {
            var dataObj = eval(json);            
            $("#qrimg").attr("src", dataObj[0].list[0].imgurl);           
            return false;
        },
        error: function (request, message, ex)
        {
            alert("错误:" + message);
        }
    });
}


四、test.ashx,没有判断目录是否存在等问题,请自行建立或者更改代码。

复制代码 代码如下:

using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Text.RegularExpressions;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using ThoughtWorks.QRCode.Codec.Util;
public class test : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string cmd = context.Request["cmd"] == null ? "get" : context.Request["cmd"].ToString();
        string filename = string.Empty;
        string filepath = string.Empty;
        switch (cmd)
        {
            case "get":
                if (context.Request.Files.Count > 0)
                {
                    for (int j = 0; j < context.Request.Files.Count; j++)
                    {
                        filename = Guid.NewGuid().ToString() + "_tmp.jpg";
                        filepath = context.Server.MapPath(@"~\Utilty\QRCode\upload") + "\\" + filename;
                        string qrdecode = string.Empty;
                        HttpPostedFile uploadFile = context.Request.Files[j];
                        uploadFile.SaveAs(filepath);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzzzj.html