Witam. Chciałem zrobić stronę, która po wciśnięciu jakiegoś linka z menu wczyta jakiś dokument bez przeładowania całego dokumentu. Użyłem w tym celu AJAX'a, lecz nie mam pojęciu czemu skrypt, który napisałem nie działa:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl" dir="ltr">
<head>
<title>Moja pierwsza strona w XHTML</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
<meta http-equiv="Content-Language" content="pl"/>
<style type="text/css">
#container
{
width: 804px;
height: 600px;
margin: 1em auto;
border: 1px solid red;
overflow: hidden;
}
#menu
{
float: left;
width: 300px;
border: 1px solid red;
height: 600px;
}
#content
{
float: right;
width: 500px;
height: 600px;
border: 1px solid red;
}
</style>
<script type="text/javascript">
var r;
var e;
function onClickFunction(link,id)
{
if (r = getXMLHttpRequest()) {
e = document.getElementById(id);
r = new HMLHttpRequest();
r.open('GET',link);
r.onreadystatechange = odbierzDane;
r.send(null);
}
}
function odbierzDane()
{
if(r.readyState == 4){
if(r.status == 200 || r.status == 304){
e.innerHTML = r.responseText;
}
}
}
</script>
</head>
<body>
<div id="container">
<div id="menu">
<ul>
<li><a onclick="onClickFunction('text.xhtml','content');" href="#">Link1</a></li>
<li><a onclick="" href="#">Link2</a></li>
</ul>
</div>
<div id="content">
</div>
</div>
</body>
</html>
Dokument, który ma się wczytać to:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<p>Jakis text</p>
Proszę o pomoc.
Ten post edytował Zyggmunt 30.05.2009, 21:45:54