Hi there, I'm very new to AJAX and can't manage to work this out, so any help would be fantastic.
I want to be able to change the content of a DIV (the text within it) once a link is pressed. I was doing it with an onclick method but I don't want the page to jump to the top.
I found this which I'm guessing is along the same lines, but i don't want to call a text/XML document... i would like a php string to be echoed instead. Is this possible?
Code:
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
It is beyond my abilities and I have been trying this for the last few hours so any advice would be great.
thank you!!
Pat.