Java 单击ShowiFrame
我有一个地图,你可以点击位置来获取该地区的信息,我想在点击时在同一页面的Iframe中显示这些信息 我的页面现在有这个链接Java 单击ShowiFrame,java,ajax,Java,Ajax,我有一个地图,你可以点击位置来获取该地区的信息,我想在点击时在同一页面的Iframe中显示这些信息 我的页面现在有这个链接 `<AREA SHAPE="CIRCLE" COORDS="555,142,6" HREF="http://www.Page.com" TITLE="" />` `` 任何建议AJAX的妙处在于,您实际上不需要使用IFRAME来实现这一点 您有一个服务器,它将向您返回有关某个区域的信息。每个区域标记只需要一个onclick属性,该属性调用一个JavaScri
`<AREA SHAPE="CIRCLE" COORDS="555,142,6" HREF="http://www.Page.com" TITLE="" />`
``
任何建议AJAX的妙处在于,您实际上不需要使用
IFRAME
来实现这一点
您有一个服务器,它将向您返回有关某个区域的信息。每个区域
标记只需要一个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>
函数getAreaInfo(id)
{
var infoBox=document.getElementById(“infoBox”);
if(infoBox==null)返回true;
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=函数(){
如果(xhr.readyState!=4)返回;
如果(xhr.status!=200)警报(xhr.status);
infoBox.innerHTML=xhr.responseText;
};
open(“GET”、“info.php?id=“+id,true”);
xhr.send(空);
返回false;
}
#信息箱{
边框:1px实心#777;
高度:400px;
宽度:400px;
}
AJAX测试
点击一个链接。。。
这里是信息的去向
下面是info.php,它将信息返回到HTML页面:
<?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.";
?>
希望这有帮助