Ajax Dynamic loading database sample _ajax Related

Source: Internet
Author: User
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;
}
}

}
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.