Posted By

maceblue on 07/30/12


Tagged

ajax


Versions (?)

ajaxRequest


 / Published in: JavaScript
 

ajax

  1. function ajaxRequest(target, method, params, callback, graph) {
  2. var xmlhttp=false;
  3. if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  4. try {
  5. xmlhttp = new XMLHttpRequest();
  6. } catch (e) {
  7. xmlhttp=false;
  8. }
  9. }
  10. if (!xmlhttp && window.createRequest) {
  11. try {
  12. xmlhttp = window.createRequest();
  13. } catch (e) {
  14. xmlhttp=false;
  15. }
  16. }
  17.  
  18. xmlhttp.onreadystatechange = function() {
  19. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  20. window[callback](xmlhttp.responseText);
  21. } else if (xmlhttp.status.toString().substring(0,1) == 3 || xmlhttp.status.toString().substring(0,1) == 4) {
  22. message('Die Anfrage lieferte kein Resultat.', true);
  23. }
  24. };
  25.  
  26. xmlhttp.open(method, target, true);
  27. if ((method == 'POST' || method == 'post') && params.length > 0) {
  28. xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  29. xmlhttp.setRequestHeader("Content-length", params.length);
  30. xmlhttp.setRequestHeader("Connection", "close");
  31.  
  32. xmlhttp.send(params);
  33. } else {
  34. xmlhttp.send(null);
  35. }
  36. }

Report this snippet  

You need to login to post a comment.