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.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo