Ajax - using the script to load different 'events' -
i new ajax, have code change content area of site once link clicked.
trouble is, want load different content using different buttons, current code allowing me link 1 file/page.
<script> function loadxmldoc() { var xmlhttp; if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("centrecont").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","../home/indexfav.php",true); xmlhttp.send(); } </script>
you can see in above script when link script ajax direct '../home/indexfav.php'.
i want use different links load different content. how can done?
here's html:
<div class="" onclick="loadxmldoc()">everyone</div> <div class="" onclick="loadxmldoc()">favourites only</div>
this how can add "argument" ajax function can call differing values. javascript below:
<script> function loadxmldoc(pagename) { var xmlhttp; if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("centrecont").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","../home/" + pagename + ".php",true); xmlhttp.send(); } </script>
then html could/would this:
<div class="" onclick="loadxmldoc('indexeveryone')">everyone</div> <div class="" onclick="loadxmldoc('indexfav')">favourites only</div>
hope helps.