Advertisement
Guest User

Untitled

a guest
Mar 9th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // here we define global variable
  2. var ajaxdestination="";
  3.  
  4. function getdata(what,where) { // get data from source (what)
  5.  try {
  6.    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  7.         new ActiveXObject("Microsoft.XMLHTTP");
  8.  }
  9.  catch (e) { /* do nothing */ }
  10.  
  11.  document.getElementById(where).innerHTML ="<center><img src='loading.gif'></center>";
  12. // we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
  13.  ajaxdestination=where;
  14.  xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
  15.  xmlhttp.open("GET", what+"?rnd="+Math.random());
  16.  xmlhttp.send(null);
  17.   return false;
  18. }
  19.  
  20. function triggered() { // put data returned by requested URL to selected DIV
  21.     alert('triggered');
  22.   if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
  23.     document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement