Posted By

aadsm on 01/28/09


Tagged

ajax


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jamesming
umang_nine
cjwilburn


Ajax simple call


 / Published in: JavaScript
 

  1. function ajax(url, fn, async)
  2. {
  3. var xmlhttp = new XMLHttpRequest();
  4.  
  5. if ( async )
  6. {
  7. xmlhttp.onreadystatechange = function()
  8. {
  9. if ( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
  10. {
  11. fn(xmlhttp);
  12. }
  13. }
  14. }
  15. xmlhttp.open("GET", url, async);
  16. xmlhttp.send(null);
  17.  
  18. if ( !async )
  19. {
  20. fn(xmlhttp);
  21. }
  22. }

Report this snippet  

You need to login to post a comment.