---
title: "ajax-20110502"
author: "gdccx"
date: "2011-05-02T11:27:25Z"
tags: []
categories: ["Web前端"]
slug: "ajax-20110502"
draft: false
lastmod: "2011-05-02T11:27:25Z"
id: 1026132
url: "https://gdccx.iteye.com/blog/1026132"
---

&lt;script src="jquery-1.4.2.js" type="text/javascript"&gt;&lt;/script&gt;  
    &lt;script src="jquery.popup.js" type="text/javascript"&gt;&lt;/script&gt;  
    &lt;script type="text/javascript"&gt;  
        $(function () {  
            $("#Text1").blur(function () {  
                var name = $("#Text1").val();  
                name = encodeURI(name)  
                $.post("product.ashx?name=" + name, function (data, status) {  
                    if (status == "success") {  
                        $("#Text2").val(data);  
                    }  
                });  
            });  
        });  
    &lt;/script&gt;  
&lt;/head&gt;  
&lt;body&gt;  
    &lt;input id="Text1" type="text" /&gt;&lt;input id="Text2" type="text" /&gt;  
&lt;/body&gt;

\-------------------------------------------------------------------------------

            context.Response.ContentType = "text/plain";  
            string name = context.Request.QueryString\["name"];  
      
             
            SqlConnection conn = new SqlConnection("server=.;database=student;uid=sa;pwd=123456");  
            conn.Open();  
            try  
            {  
                SqlCommand cmd = new SqlCommand("select * from product where proname='" + name + "'", conn);  
                SqlDataReader dr = cmd.ExecuteReader();  
                dr.Read();  
                context.Response.Write(dr\["proprice"].ToString());  
            }  
            catch (Exception)  
            {

                context.Response.Write("没有");  
            }