function ajaxFunction() { var xmlHttp; if(window.XMLHttpRequest) { xmlHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } else { alert("Your browser does not support AJAX!"); return false; } xmlHttp.open("GET","links.txt",true); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById('relatedLinks').innerHTML = xmlHttp.responseText; } } xmlHttp.send(null); }
<div id="relatedLinks">This will be filled with the link in links.txt.</div>
<a href="#" onclick="ajaxFunction()">Click me to change div content</a> <a href="http://www.domain.com/">The Domain!</a> xmlHttp.open("GET","getreceiver.php?foo=bar",true);
xmlHttp.send(null); xmlHttp.open("POST","postreceiver.php",true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send('foo=bar');