Ajax Post请求实例

前台JS
function OnSaveBarCodeTitle() {          
            if (document.getElementByIdx_x("Path1").value != "") {
 
                var mPDF417Text = PDF417Text.value;
                var mTitle = mPDF417Text.split("^");
                $.post("Pdf417.ashx?action=SaveCarCode", { Barcode_File: document.getElementByIdx_x("Path1").value, BarCodeDescript: mTitle[6], r: Math.random() }, 
            function (data) {
                data = eval_r(data);
            }, "json");
                alert("保存成功");
            }
            else {
                alert("请先进行‘获取图片路径’操作");
            }
 
        } 
 
  post:请求类型  Pdf417.ashx?action=SaveCarCode:一般处理程序?action=键--在一般处理程序里面对应相应的方法   Barcode_File对应流ctx.Request["Barcode_File"]
一般处理程序
 public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        if (context.Request["action"] == "GetPDF417")
        {
            GetPDF417();
        }
        else if (context.Request["action"] == "SaveCarCode")
        {
            SaveCarCode();
        }
        context.Response.Flush();
        context.Response.End();
    }
 private int mSaveCarCode(string barcode_File, string barCodeDescript)
    {
        
        SqlParameter[] para ={new SqlParameter("@BarCodeImage",barcode_File),
                              new SqlParameter("@BarCodeDescript",barCodeDescript)};
        int result = mGear.Projects.Utility.SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "dbo.CreateBsarCode", para);
       return result;
        
    }
posted @ 2016-05-06 17:27  hxkk  阅读(546)  评论(0编辑  收藏  举报