Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type = "Text/javascript" >
function Btnclick () {
var xmlhttp = xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
if (!xmlhttp) {
Alert ("Create XMLHTTP Object Exception!");
return false;
}
var Text1 = document.getElementById ("Text1");
Xmlhttp.open ("Post", "Getprice2.ashx?ts" +text1, false);
Xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
document.getElementById ("Text2"). Value = Xmlhttp.responsetext;
}
else {
Alert ("Ajax returns an error!") ");
}
}
}
Xmlhttp.send ();
}
</script>
<body>
<p>
Product Name: <input id= "Text1" type= "text"/></p>
<p>
Price: <input id= "Text2" type= "text"/></p>
<p>
<input id= "Button1" type= "button" value= "query" onclick = "Btnclick ()"/></p>
</body>
Copy Code code as follows:
<%@ WebHandler language= "C #" class= "GetPrice"%>
Using Syste M
using System.Linq;
using System.Web;
using Datasetproductstableadapters;
public class Getprice:ihttphandler {
public void ProcessRequest (HttpContext context)
{
context. Response.ContentType = "Text/plain";
//context. Response.Write ("Hello World");
String name = Context. request["Text1"];
var data = new Pricetableadapter (). Getdatabyname (name);/You need to build a strongly typed dataset
if (data). Count <= 0)
{
context. Response.Write ("None|0");
}
Else
{
context. Response.Write ("ok|" + data.) Single (). Price);
}
}
public bool IsReusable {
Get {
return false;
}
}
}