zoukankan      html  css  js  c++  java
  • JQuery AJAX 通过一般处理程序 取列表

    由于上一篇的积累 这一个就简单了

    也就是把反回了字符串 显示到table中

     $("#btnSearch").click(function () {
                    $.post("CurrentStocklist.ashx", function (result) {
                        $(".table").append(result);
                    })
                })

    这样

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    
    namespace UI
    {
        /// <summary>
        /// CurrentStockList1 的摘要说明
        /// </summary>
        public class CurrentStockList1 : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
    
                using (SqlConnection con = new SqlConnection("server =.;uid=sa;pwd=123;database=lt"))
                {
                    string s = "select top 100 c.autoid,c.cWhCode,c.cinvCode,c.iQuantity,wh.cWhName,inv.cInvName"
                          + " from currentStock c left join wareHouse wh "
                          + " on c.cWhCode =wh.cWHCode left join inventory inv on c.cInvCode =inv.cInvCode ";
    
                    using (SqlDataAdapter ada = new SqlDataAdapter(s, con))
                    {
                        DataTable dt = new DataTable();
                        ada.Fill(dt);
    
                        foreach (DataRow dr in dt.Rows)
                        {
                            StringBuilder sb = new StringBuilder();
    
                            sb.Append("<tr>");
                            sb.Append("<td>" + dr["autoid"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cwhCode"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cWHName"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cInvCode"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cInvName"].ToString() + "</td>");
                            sb.Append("<td>" + dr["iquantity"].ToString() + "</td>");
    
                            sb.Append("</tr>");
                            context.Response.Write(sb.ToString());
                        }
                    }
    
                }
    
    
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    View Code

     也可以通过传参数查询

     $("#btnSearch").click(function () {
    
                    $.post("CurrentStocklist.ashx", { whNames: $("#txtWHNameS").val(), invNames: $("#txtInvNames").val() }, function (result) {
                        $(".table").append(result);
                    })
                })

    后台代码 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    
    namespace UI
    {
        /// <summary>
        /// CurrentStockList1 的摘要说明
        /// </summary>
        public class CurrentStockList1 : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
    
                string whName = (context.Request["whNames"] ??"").ToString();
                string invName = (context.Request["invNames"] ?? "").ToString();
    
                using (SqlConnection con = new SqlConnection("server =.;uid=sa;pwd=123;database=lt"))
                {
                    string s = "select  c.autoid,c.cWhCode,c.cinvCode,c.iQuantity,wh.cWhName,inv.cInvName"
                          + " from currentStock c left join wareHouse wh "
                          + " on c.cWhCode =wh.cWHCode left join inventory inv on c.cInvCode =inv.cInvCode "
                          +"where wh.cWHName like '%"+whName+"%' and inv.cInvName like "+ "'%"+invName+"%'";
    
                    using (SqlDataAdapter ada = new SqlDataAdapter(s, con))
                    {
                        DataTable dt = new DataTable();
                        ada.Fill(dt);
    
                        foreach (DataRow dr in dt.Rows)
                        {
                            StringBuilder sb = new StringBuilder();
    
                            sb.Append("<tr>");
                            sb.Append("<td>" + dr["autoid"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cwhCode"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cWHName"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cInvCode"].ToString() + "</td>");
                            sb.Append("<td>" + dr["cInvName"].ToString() + "</td>");
                            sb.Append("<td>" + dr["iquantity"].ToString() + "</td>");
    
                            sb.Append("</tr>");
                            context.Response.Write(sb.ToString());
                        }
                    }
    
                }
    
    
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    View Code
  • 相关阅读:
    Ubuntu 指令汇总
    ROS环境下Pointgrey相机的配置方法
    BUG战斗史 —— 日期格式与字符串之间的转换
    Effective Java —— 使类和成员的可访问性最小化
    JDBC和桥接模式
    Effective Java —— 覆盖equals时总要覆盖hashCode
    AutoValue —— Generated immutable value classes
    Effective Java —— 覆盖equals时遵守通用约定
    Effective Java —— try-with-resources 优先于 try-finally
    Effective Java —— 消除过期的对象引用
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/8657287.html
Copyright © 2011-2022 走看看