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
  • 相关阅读:
    Java多线程(3) Volatile的实现原理
    Java 多线程(2)-Executor
    Java 多线程(1)-Thread和Runnable
    nginx+php部署
    MySQL的慢查询分析
    MySQL 错误
    log4j.properties配置详解
    Windows下Nginx的安装与配置(转)
    Java 字符的验证
    Spring MVC3返回JSON数据中文乱码问题解决(转)
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/8657287.html
Copyright © 2011-2022 走看看