復(fù)制代碼 代碼如下:
!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>
title>/title>
script type ="text/javascript">
function btnClick() {
var xmlhttp = xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlhttp) {
alert("創(chuàng)建xmlhttp對(duì)象異常!");
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返回錯(cuò)誤!");
}
}
}
xmlhttp.send();
}
/script>
/head>
body>
p>
產(chǎn)品名稱:input id="Text1" type="text" />/p>
p>
價(jià)格:input id="Text2" type="text" />/p>
p>
input id="Button1" type="button" value="查詢" onclick = "btnClick()"/>/p>
/body>
/html>
復(fù)制代碼 代碼如下:
%@ WebHandler Language="C#" Class="GetPrice" %>
using System;
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);//需要建一個(gè)強(qiáng)類型的dataset
if (data.Count = 0)
{
context.Response.Write("none|0");
}
else
{
context.Response.Write("ok|" + data.Single().Price);
}
}
public bool IsReusable {
get {
return false;
}
}
}
您可能感興趣的文章:- 通過Spring Boot配置動(dòng)態(tài)數(shù)據(jù)源訪問多個(gè)數(shù)據(jù)庫的實(shí)現(xiàn)代碼
- 詳解SpringBoot 創(chuàng)建定時(shí)任務(wù)(配合數(shù)據(jù)庫動(dòng)態(tài)執(zhí)行)
- asp.net實(shí)現(xiàn)的MVC跨數(shù)據(jù)庫多表聯(lián)合動(dòng)態(tài)條件查詢功能示例
- Java的MyBatis框架中對(duì)數(shù)據(jù)庫進(jìn)行動(dòng)態(tài)SQL查詢的教程
- Yii操作數(shù)據(jù)庫實(shí)現(xiàn)動(dòng)態(tài)獲取表名的方法
- C#動(dòng)態(tài)創(chuàng)建Access數(shù)據(jù)庫及表的方法
- ext combobox動(dòng)態(tài)加載數(shù)據(jù)庫數(shù)據(jù)(附前后臺(tái))
- c# asp .net 動(dòng)態(tài)創(chuàng)建sql數(shù)據(jù)庫表的方法
- javascript動(dòng)態(tài)添加表格數(shù)據(jù)行(ASP后臺(tái)數(shù)據(jù)庫保存例子)
- Mysql動(dòng)態(tài)更新數(shù)據(jù)庫腳本的示例講解