52,782
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ajax test</title>
<script type="text/jscript" src="ajax.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
Question:<input type="text" onkeyup="doIt(this.value)" />
</div>
<div>
<asp:TextBox ID="show" runat="server" Width="500px" Height="70px"></asp:TextBox>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>get value</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class getValue : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = "Data Source=MINFO66;Persist Security Info=True;User ID=minfodb;Password=minfodba;Unicode=True";
System.Data.OracleClient.OracleConnection oracle_conn = null;
System.Data.OracleClient.OracleCommand oracle_cmd = null;
try
{
string question_title = Request.QueryString["question_title"];
oracle_conn = new System.Data.OracleClient.OracleConnection(connectionString);
oracle_cmd = oracle_conn.CreateCommand();
oracle_conn.Open();
oracle_cmd.CommandText = @"SELECT QUESTION_TITLE
FROM BAIDUZHIDAO_QUESTIONS
WHERE QUESTION_TITLE LIKE '" + question_title + "%';";
string result = Convert.ToString(oracle_cmd.ExecuteScalar());
//Console.Write(result);
Response.Write(result);
Response.End();
}
catch (Exception excpt)
{
Response.Write(excpt);
}
finally
{
if (oracle_cmd != null)
{
oracle_cmd.Cancel();
oracle_cmd.Dispose();
}
if (oracle_conn != null)
{
oracle_conn.Close();
oracle_conn.Dispose();
}
}
}
}
// JScript 文件
var xmlHttp;
function getXMLHttpObject()
{
var xmlHttp = null;
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function stateChanged()
{
if (xmlHttp.readyState == 4)
{
document.getElementById("show").value = xmlHttp.responseText;
}
}
function doIt(value)
{
if (value.length == 0)
{
return ;
}
xmlHttp = getXMLHttpObject();
if (xmlHttp == null)
return ;
var url = "getValue.aspx";
url = url + "?question_title=" + value;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.send(null);
}