testAjax.htm 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title></title>
  5. <script type="text/javascript">
  6. window.onload = function () {
  7. ajax("http://d-back.1473.cn:1337", ["selectAll","1","2"], function (r) {
  8. alert(r);
  9. });
  10. }
  11. ajax = function (url, arg, callback) {
  12. var arg = "mode=" + arg.join();
  13. var _xmr;
  14. //从已经存在的ajax对象中找到已经结束请求的ajax对象,重新使用,避免ajax对象没有释放,重新创建的问题。
  15. _xmr = findExistAjax();
  16. //兼容返回所有的浏览器的ajax
  17. _xmr = compileBrowser();
  18. //值兼容chrome
  19. var _xmr = new XMLHttpRequest();
  20. _xmr.open("POST", url);
  21. _xmr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  22. _xmr.send(arg);
  23. _xmr.onreadystatechange = function () {
  24. if (this.readyState == 4 && this.status == 200) {
  25. callback ? callback(this.resonseText) : "";
  26. }
  27. }
  28. }
  29. </script>
  30. </head>
  31. <body>
  32. </body>
  33. </html>