awtAjax.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var xmlHttpRequest = null;
  2. var AwtResult = null;
  3. //Awt ajax통신 객체 생성
  4. function xmlHttpPost()
  5. {
  6. //IE인경우
  7. if(window.ActiveXObject)
  8. {
  9. xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
  10. }
  11. else
  12. {
  13. alert("Err");
  14. }
  15. }
  16. //Awt서버에 보낼 구문 패턴을 만드는 함수
  17. function XMLPattern(strSpell, strFlag, searchCount)
  18. {
  19. var strXML = null;
  20. if (searchCount == null)
  21. strXML = encodeURI("strSpell="+strSpell+"&strFlag="+strFlag);
  22. else
  23. strXML = encodeURI("strSpell="+strSpell+"&strFlag="+strFlag +"&searchCount=" + searchCount);
  24. return strXML;
  25. }
  26. //Awt서버에 ajax요청을 보내는 함수
  27. function send(AwtAjaxUrl, strSpell, strFlag, searchCount)
  28. {
  29. var strPostValue=XMLPattern(strSpell,strFlag,searchCount);
  30. xmlHttpRequest.open('POST', AwtAjaxUrl, true);
  31. xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  32. xmlHttpRequest.setRequestHeader("Cache-Control", "no-cache");
  33. xmlHttpRequest.setRequestHeader("Pragma", "no-cache");
  34. xmlHttpRequest.onreadystatechange = function() {
  35. if(xmlHttpRequest.readyState == 4)
  36. {
  37. switch (xmlHttpRequest.status)
  38. {
  39. case 404:
  40. //alert('오류: ' + AwtAjaxUrl + '이 존재하지 않음');
  41. break;
  42. case 200:
  43. OnResult(xmlHttpRequest.responseText.trim());
  44. break;
  45. default:
  46. //alert('오류: ' + xmlHttpRequest.responseText);
  47. break;
  48. }
  49. }
  50. }
  51. xmlHttpRequest.send(strPostValue);
  52. }
  53. String.prototype.trim = function ()
  54. {
  55. return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  56. }