Ajax simple call


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.