0
我有一张地图,你可以上的位置点击获取信息,这方面的,我想显示在同一页面中的iframe的信息点击上单击显示的Iframe
时我的页面有这样的链接现在
`<AREA SHAPE="CIRCLE" COORDS="555,142,6" HREF="http://www.Page.com" TITLE="" />`
任何建议
我有一张地图,你可以上的位置点击获取信息,这方面的,我想显示在同一页面中的iframe的信息点击上单击显示的Iframe
时我的页面有这样的链接现在
`<AREA SHAPE="CIRCLE" COORDS="555,142,6" HREF="http://www.Page.com" TITLE="" />`
任何建议
AJAX的好处是,你并不真的需要一个IFRAME
做到这一点。
你有一个服务器,将返回给你有关某一领域的信息。每个AREA
标签都只需要一个onclick
属性,该属性调用JavaScript函数来检索该信息并将其显示在您在页面上放置的位置。
下面是一个简单的HTML页面将使用AJAX
<html>
<head>
<script type="text/javascript">
function getAreaInfo(id)
{
var infoBox = document.getElementById("infoBox");
if (infoBox == null) return true;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
if (xhr.status != 200) alert(xhr.status);
infoBox.innerHTML = xhr.responseText;
};
xhr.open("GET", "info.php?id=" + id, true);
xhr.send(null);
return false;
}
</script>
<style type="text/css">
#infoBox {
border:1px solid #777;
height: 400px;
width: 400px;
}
</style>
</head>
<body onload="">
<p>AJAX Test</p>
<p>Click a link...
<a href="info.php?id=1" onclick="return getAreaInfo(1);">Area One</a>
<a href="info.php?id=2" onclick="return getAreaInfo(2);">Area Two</a>
<a href="info.php?id=3" onclick="return getAreaInfo(3);">Area Three</a>
</p>
<p>Here is where the information will go.</p>
<div id="infoBox"> </div>
</body>
</html>
从服务器获取信息,而这里是回信息返回到HTML页面info.php的:
<?php
$id = $_GET["id"];
echo "You asked for information about area #{$id}. A real application would look something up in a database and format that information using XML or JSON.";
?>
希望这可以帮助!