手写ajax获取数据库中的数据 aspx页面,根据产品名称获取数据库中存储的数量就是一文本框 输入 商品名称后 点击按钮 后面显示该商品数量页面所有的控件都为html控件,请问用ajax如何实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道楼主说手写是什么意思。用jQuery就可以,而且很方便。 var xmlHttp = false;function myXMLHttpRequest() { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { xmlHttp = false; } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); } return xmlHttp;}function pubajax(productName) { var url = "../Default.aspx?productName=" +productName ; //要请求的服务端地址 myXMLHttpRequest() if (xmlHttp) //成功创建xmlhttprequest { xmlHttp.open("GET", url, true); //与服务端建立连接(请求方式post或get,地址,true表示异步) xmlHttp.onreadystatechange = callback; //指定回调函数 xmlHttp.send(null); //发送请求 }}function callback() //回调函数,对服务端的响应处理,监视response状态{ if (xmlHttp.readystate == 4) //请求状态为4表示成功 { if (xmlHttp.status == 200) //http状态200表示OK { Dispaly(); //所有状态成功,执行此函数,显示数据 } else //http返回状态失败 { // alert("服务端返回状态" + xmlHttp.statusText); } } else //请求状态还没有成功,页面等待 { //"数据加载中"; }}function Dispaly() //接受服务端返回的数据,对其进行显示{ alert(xmlHttp.responseText);//xmlHttp.responseText返回的结果}在Default.aspx页面中 protected void Page_Load(object sender, EventArgs e) { Response.CacheControl = "no-cache"; string productName= Request.QueryString["productName"]; //根据productName取得数量 Response.write(数量) } <script type="text/javascript"> var xmlHttp; function createXMLHttpRequest() { if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function CheckUserName() { var us=document.getElementById("txtname").value; if(us!="") { createXMLHttpRequest(); var url= "RegistValidate.ashx?name="+escape(document.getElementById("txtname").value); xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=ShowResult; xmlHttp.send(null); } } function ShowResult() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var s; s=xmlHttp.responseText; document.getElementByid("txT").value=s; } } } </script> public class RegistValidate : IHttpHandler { public void ProcessRequest(HttpContext context) { string name = HttpUtility.UrlDecode(context.Request.QueryString["name"].ToString()); if (查询) { context.Response.Write(name); } else { context.Response.Write(""); } System.Threading.Thread.Sleep(1000); } public bool IsReusable { get { return false; } } } 令人头疼的vs2010新问题,如何解决? !!!!!!!!!在asp.net中如何把.swf格式的flash图片作为背景图片 登陆密码 输错 限制? 我想把多次提交得到的记录存在一个DataTable中,该如何实现? 数据库连接问题 Gridview导出到Excel 但比较长的数值类型导出后会显示不完整 该如何解决? 急!FreeTextBox在线编辑器问题 为什么只能修改部分纪录 大家能讲讲聊天室的原理吗?怎么才能够实时的互动聊天呢? 用JavaScript写的控件如何从服务器端取出数据 urlrewrite UpdatePanel共存的问题 datatable排序显示问题,求助~~~~~
用jQuery就可以,而且很方便。
function myXMLHttpRequest() { try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}function pubajax(productName) {
var url = "../Default.aspx?productName=" +productName ; //要请求的服务端地址 myXMLHttpRequest()
if (xmlHttp) //成功创建xmlhttprequest
{
xmlHttp.open("GET", url, true); //与服务端建立连接(请求方式post或get,地址,true表示异步)
xmlHttp.onreadystatechange = callback; //指定回调函数
xmlHttp.send(null); //发送请求
}
}function callback() //回调函数,对服务端的响应处理,监视response状态
{
if (xmlHttp.readystate == 4) //请求状态为4表示成功
{
if (xmlHttp.status == 200) //http状态200表示OK
{
Dispaly(); //所有状态成功,执行此函数,显示数据
}
else //http返回状态失败
{
// alert("服务端返回状态" + xmlHttp.statusText);
}
}
else //请求状态还没有成功,页面等待
{
//"数据加载中";
}
}function Dispaly() //接受服务端返回的数据,对其进行显示
{
alert(xmlHttp.responseText);//xmlHttp.responseText返回的结果
}
在Default.aspx页面中
protected void Page_Load(object sender, EventArgs e)
{
Response.CacheControl = "no-cache";
string productName= Request.QueryString["productName"];
//根据productName取得数量
Response.write(数量)
}
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function CheckUserName()
{
var us=document.getElementById("txtname").value;
if(us!="")
{
createXMLHttpRequest();
var url= "RegistValidate.ashx?name="+escape(document.getElementById("txtname").value);
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=ShowResult;
xmlHttp.send(null);
}
}
function ShowResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var s;
s=xmlHttp.responseText;
document.getElementByid("txT").value=s;
}
}
}
</script> public class RegistValidate : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
string name = HttpUtility.UrlDecode(context.Request.QueryString["name"].ToString());
if (查询)
{
context.Response.Write(name);
}
else
{
context.Response.Write("");
}
System.Threading.Thread.Sleep(1000);
} public bool IsReusable
{
get
{
return false;
}
}
}