Javascript AJAX鼠标悬停在图像上,显示HTML内容
我尝试使用AJAX在图像上滑动鼠标时显示html内容。我的代码看起来不错,但似乎不起作用。deakin campus/discover deakin是我试图显示的html页面 下面的代码没有显示任何内容,但是如果我在代码中添加了一些警报;将显示html文本Javascript AJAX鼠标悬停在图像上,显示HTML内容,javascript,html,ajax,image,mouseover,Javascript,Html,Ajax,Image,Mouseover,我尝试使用AJAX在图像上滑动鼠标时显示html内容。我的代码看起来不错,但似乎不起作用。deakin campus/discover deakin是我试图显示的html页面 下面的代码没有显示任何内容,但是如果我在代码中添加了一些警报;将显示html文本 <?xml version = "1.0" encoding = "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" >
var asyncRequest;
function getContent(url)
{
try
{
asyncRequest = new XMLHttpRequest();
asyncRequest.open( 'GET', url, true );
asyncRequest.send(null);
asyncRequest.onreadystatechange = stateChange();
}
catch (exception)
{
alert("error");
}
}
function stateChange()
{
if (asyncRequest.readyState == 4 && asyncRequest.status == 200)
{
document.getElementById('ContentArea').innerHTML= asyncRequest.responseText;
}
}
function clearContent()
{
document.getElementById('ContentArea').innerHTML = '';
}
</script>
</head>
<body>
<img src="deakin-campus.jpg" width="71" height="71"
onmouseover = 'getContent("deakin-campus.html")'
onmouseout = 'clearContent()' />
<img src="discover-deakin.jpg" width="71" height="71"
onmouseover = 'getContent("discover-deakin.html")'
onmouseout = 'clearContent()' />
<div id="ContentArea"> </div>
</body>
</html>
var异步请求;
函数getContent(url)
{
尝试
{
asyncRequest=新的XMLHttpRequest();
asyncRequest.open('GET',url,true);
asyncRequest.send(空);
asyncRequest.onreadystatechange=stateChange();
}
捕获(例外)
{
警报(“错误”);
}
}
函数stateChange()
{
如果(asyncRequest.readyState==4&&asyncRequest.status==200)
{
document.getElementById('ContentArea')。innerHTML=asyncRequest.responseText;
}
}
函数clearContent()
{
document.getElementById('ContentArea')。innerHTML='';
}
传递函数引用。。。所以没有“()”
在调用send方法之前也要执行此操作
asyncRequest.onreadystatechange = stateChange;