其实我的要求很简单:页面上有两个按钮,鼠标放到第一个按钮上,弹出一个悬浮窗,悬浮窗里面显示出第一个按钮对应的数据库中“联系人”、“联系电话”两项,都是数据库中的数据。第二个按钮同理。。 多谢!我不是等现成的,而是我想好好学习学习,之前学过编程,由于一些差错之间两年没有做软件开发,所以全忘了,我想重新开始。。希望前辈们指点!
半个多月了,我在网上查一些关于AJAS的信息,学习视频,自己写了一段代码,失败了,我觉得现在给我一段写好的代码只有这样我才能更好的理解ajax。
用vs开发,数据库用sql server。
<script>
function getPos(o) {
var p = { y: o.offsetHeight+o.offsetTop, x: o.offsetLeft };
while (o = o.offsetParent) { p.y += o.offsetTop; p.x += o.offsetLeft; }
return p;
}
function readInfo(id, a) {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("microsoft.xmlhttp");
xhr.open("get", "xxx.ashx?id="+id+'&_='+new Date().getTime(), true);
xhr.onreadystatechange = function () {
if (4 == xhr.readyState) {
if (200 == xhr.status || 0 == xhr.status) {
var pop = document.getElementById('pop'), p = getPos(a);
pop.style.left = p.x + 'px'; pop.style.top = p.y + 'px';
pop.innerHTML = xhr.responseText;//设置浮动层内容为ajax返回值
pop.style.display = 'block';
}
else alert('动态页有问题\n\n' + xhr.responseText);
}
}
xhr.send(null);
}
window.onload = function () { document.getElementById('pop').onmouseout = function () { this.style.display = 'none'; } }
#pop{position:absolute;border:solid 1px #000;display:none;background:#fff;width:200px;}xxx.ashx
public void ProcessRequest(HttpContext context)
{
string id=context.Request.QueryString["id"];//获取ajax提交的id参数,你依据id读取数据库输出联系人和联系电话就行
context.Resonse.Write("联系人:xxxx<br />联系电话:xxxxx");
}
晕。。。插入代码怎么直接显示成html对象了。。
function getPos(o) { var p = { y: o.offsetHeight+o.offsetTop, x: o.offsetLeft }; while (o = o.offsetParent) { p.y += o.offsetTop; p.x += o.offsetLeft; } return p; } function readInfo(id, a) { var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("microsoft.xmlhttp"); xhr.open("get", "xxx.ashx?id="+id+'&_='+new Date().getTime(), true); xhr.onreadystatechange = function () { if (4 == xhr.readyState) { if (200 == xhr.status || 0 == xhr.status) { var pop = document.getElementById('pop'), p = getPos(a); pop.style.left = p.x + 'px'; pop.style.top = p.y + 'px'; pop.innerHTML = xhr.responseText;//设置浮动层内容为ajax返回值 pop.style.display = 'block'; } else alert('动态页有问题\n\n' + xhr.responseText); } } xhr.send(null); } window.onload = function () { document.getElementById('pop').onmouseout = function () { this.style.display = 'none'; } } #pop{position:absolute;border:solid 1px #000;display:none;background:#fff;width:200px;}