...

simple ajax replace but with many links

alapimba
11-05-2007, 03:57 PM
Hello, can anyone help me with this function?

i'm doing a replace, the content appears inside the div "foo".

now i want to have like 3 or 4 links with the funcione replace and each one replace his own content.

my code so far and working is:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function replace() {
http.open("GET", "conteudo.php?id=1", true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('foo').innerHTML = http.responseText;
}
}
http.send(null);
}
</script>

</head>
<body>
<div class="accordion_content">
<h2><p><a href="javascript:replace()">link 1</a></p>
<div id="foo">
here appear the content
</div></h2>
</body>

shyam
11-06-2007, 04:51 AM
use function parameters
function replace(where, what) {
http.open("GET", "conteudo.php?id=" + what, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById(where).innerHTML = http.responseText;
}
}
http.send(null);
}

<a href="javascript:replace('foo', 1)">link 1</a>

alapimba
11-06-2007, 11:53 AM
thank you :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum