topical media & game development

talk show tell print

lib-ajax-example-relay-page.htm / htm



  <head>
  <script type="text/javascript" language="javascript">
  function ReplaceElementID(url,id)
  {
          var httpRequest;
          if (window.XMLHttpRequest)
          {
                  try { httpRequest = new XMLHttpRequest(); }
                  catch(e) {}
          }
          else if (window.ActiveXObject)
          {
                  try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
                  catch(e)
                  {
                          try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
                          catch(e) {}
                  }
          }
          if(! httpRequest)
          {
                  alert('\n\nGiving up :(\n\nCannot create an AJAX connection.');
                  return false;
          }
          httpRequest.onreadystatechange = function() { ContainerContents(httpRequest,id); };
          httpRequest.open('GET',url,true);
          httpRequest.send('');
  } // function makeRequestGET()
  
  function ContainerContents(content,id)
  {
          try
          {
                  if (content.readyState == 4)
                  {
                          if(content.status == 200) { document.getElementById(id).innerHTML=content.responseText; }
                          else { alert('\n\nThere was a problem with the request.\n\nStatus code: '+content.status+'\n'+content.statusText); }
                  }
          }
          catch(error) { alert('Error: '+error.name+' -- '+error.message); }
  } // function ContainerContents()
  </script>
  </head>
  <body>
  see http://www.webreference.com/programming/javascript/w_b/index.html
  >
  <div id="AnIdentification">
  <p>
  Hi, I am text that will be replaced.
  </p>
  </div>
  <a href="javascript:ReplaceElementID('lib-ajax-example-relay-one.htm','AnIdentification')">
  Click to see it in action.
  </a>
  Alternatively, click 
  <a href="javascript:ReplaceElementID('lib-ajax-example-relay-two.htm','AnIdentification')">
  two
  </a>
  <h4>external reference(s)</h4>
  using php:
   <a href="javascript:ReplaceElementID('lib-ajax-example-relay.php?http://www.cs.vu.nl/~eliens/media/ajax.txt','AnIdentification')">
  Click to grab file.txt from another domain 
  </a>
  or using
  <a href="javascript:ReplaceElementID('lib-ajax-example-relay-relay.cgi?http://www.cs.vu.nl/~eliens/media/ajax.txt','AnIdentification')">cgi</a>
  </body>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.