Ajax動態(tài)加載數(shù)據(jù)庫示例
更新時間:2014年05月18日 17:18:32 作者:
這篇文章主要介紹的是一個Ajax動態(tài)加載數(shù)據(jù)庫示例,需要的朋友可以參考下
復(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對象異常!");
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返回錯誤!");
}
}
}
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);//需要建一個強(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配置動態(tài)數(shù)據(jù)源訪問多個數(shù)據(jù)庫的實(shí)現(xiàn)代碼
- 詳解SpringBoot 創(chuàng)建定時任務(wù)(配合數(shù)據(jù)庫動態(tài)執(zhí)行)
- asp.net實(shí)現(xiàn)的MVC跨數(shù)據(jù)庫多表聯(lián)合動態(tài)條件查詢功能示例
- Java的MyBatis框架中對數(shù)據(jù)庫進(jìn)行動態(tài)SQL查詢的教程
- Yii操作數(shù)據(jù)庫實(shí)現(xiàn)動態(tài)獲取表名的方法
- C#動態(tài)創(chuàng)建Access數(shù)據(jù)庫及表的方法
- ext combobox動態(tài)加載數(shù)據(jù)庫數(shù)據(jù)(附前后臺)
- c# asp .net 動態(tài)創(chuàng)建sql數(shù)據(jù)庫表的方法
- javascript動態(tài)添加表格數(shù)據(jù)行(ASP后臺數(shù)據(jù)庫保存例子)
- Mysql動態(tài)更新數(shù)據(jù)庫腳本的示例講解
相關(guān)文章
妙用Ajax技術(shù)實(shí)現(xiàn)局部刷新商品數(shù)量和總價(jià)實(shí)例代碼
這篇文章主要給大家介紹妙用Ajax技術(shù)實(shí)現(xiàn)局部刷新商品數(shù)量和總價(jià)實(shí)例代碼,非常不錯,需要的朋友一起看看吧2016-05-05Ajax 框架之SSM整合框架實(shí)現(xiàn)ajax校驗(yàn)
這篇文章主要介紹了Ajax 框架之SSM整合框架實(shí)現(xiàn)ajax校驗(yàn),需要的朋友可以參考下2017-04-04登錄超時給出提示跳到登錄頁面(ajax、導(dǎo)入、導(dǎo)出)
這篇文章主要介紹了登錄超時給出提示跳到登錄頁面(ajax、導(dǎo)入、導(dǎo)出)的相關(guān)資料,需要的朋友可以參考下2016-02-02Ajax的原生實(shí)現(xiàn)關(guān)于MIME類型的使用方法
下面小編就為大家分享一篇Ajax的原生實(shí)現(xiàn)關(guān)于MIME類型的使用方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03基于CORS實(shí)現(xiàn)WebApi Ajax 跨域請求解決方法
這篇文章主要介紹了基于CORS實(shí)現(xiàn)WebApi Ajax 跨域請求解決方法,需要的朋友可以參考下2017-08-08