分类:
2008-06-24 23:02:17
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
<html><head>
<title>TechRepublic.com Exampletitle>
<scrīpt type="text/javascrīpt" language="Javascrīpt">
function getTelephone(cName) {document.body.style.cursor='wait';varobj = null;
if (window.XMLHttpRequest) {obj = new XMLHttpRequest();
} else if (window.ActiveXObject) {obj = new ActiveXObject("Microsoft.XMLHTTP");
}vargoUrl = "" + cNameobj.open("POST",goUrl, false );obj.send();
if ((obj.responseText == "Error") || (obj.responseText == ""))
alert("The company name is invalid.");
elsethis.document.forms[0].telephone.value = obj.responseText;document.body.style.cursor='auto';
}
scrīpt>head><body>
<form id="frmText">
<input type="text" name="telephone" /><br />
<input type="text" name="cname" onblur="getTelephone(this.value);" />
form>
body>html>
<%@ Page Language="C#" ContentType="text/plain" Debug="true" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<scrīpt language="C#" runat="server">
private SqlConnection conn = null;
private SqlCommand cmd = null;
private String connString;
private String strSQL;
private void Page_Load(object sender, System.EventArgs e) {
if (!IsPostBack) {
connString = "data source=SALESLAPTOP;uid=test;pwd=test;initial catalog=Northwind";
strSQL = "SELECT Phone FROM dbo.Customers WHERE CompanyName LIKE '%" + Request.QueryString["cname"] + "%'";
try {
conn = new SqlConnection(connString);
cmd = new SqlCommand(strSQL, conn);
conn.Open();
Response.Write(cmd.ExecuteScalar().ToString());
conn.Close();
}catch (Exception ex) {Response.Write("Error");
} finally {
if (conn.State == ConnectionState.Open) {
conn.Close();
}conn.Dispose();
} } }
scrīpt>