You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.0 KiB

  1. wn.xmlhttp = {
  2. request: function() {
  3. if ( window.XMLHttpRequest ) // Gecko
  4. return new XMLHttpRequest() ;
  5. else if ( window.ActiveXObject ) // IE
  6. return new ActiveXObject("MsXml2.XmlHttp") ;
  7. },
  8. complete: function(req, callback, url) {
  9. if (req.status==200 || req.status==304) {
  10. callback(req.responseText);
  11. } else {
  12. alert(url +' request error: ' + req.statusText + ' (' + req.status + ')' ) ;
  13. }
  14. },
  15. get: function(url, callback, args, async) {
  16. // async by default
  17. if(async === null) async=true;
  18. var req = wn.xmlhttp.request();
  19. // for async type
  20. req.onreadystatechange = function() {
  21. if (req.readyState==4) {
  22. wn.xmlhttp.complete(req, callback, url)
  23. }
  24. }
  25. // separator can be & or ?
  26. // based on if there are already arguments
  27. var sep = ((args && args.indexOf('?'))==-1) ? '?' : '&';
  28. // add arguments to url
  29. var u = args ? (url + sep + args) : url;
  30. // call the server
  31. req.open('GET', u, async);
  32. req.send(null);
  33. // for sync
  34. if(!async) {
  35. wn.xmlhttp.complete(req, callback, url)
  36. }
  37. }
  38. }