• 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
  • 相关阅读:
    关于ng路由的传参问题(传递一个,多个参数)
    ng指令控制一个元素的影藏的与显示几种方法的使用
    将一个对象push到数组之中的几点问题
    关于ng的路由的几点想法(ui-view)
    angularJS自定义一个过滤器
    ng自带的表单验证
    实现标签的添加与删除(tags)
    关于ng-class,ng-style的用法
    5分钟搞懂:session与cookie
    前端浏览器的两种缓存:协商缓存和强缓存
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/8657287.html
Copyright © 2020-2023  润新知