ajaxEx.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var xmlHttpRequest = null;
  2. var AwtResult = null;
  3. function xmlHttpPost()
  4. {
  5. //IE인경우
  6. if(window.ActiveXObject)
  7. {
  8. xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
  9. }
  10. else
  11. {
  12. alert("Err");
  13. }
  14. }
  15. function XMLPattern(strSpell, strFlag, searchCount)
  16. {
  17. var strXML = null;
  18. if (searchCount == null)
  19. strXML = encodeURI("strSpell="+strSpell+"&strFlag="+strFlag);
  20. else
  21. strXML = encodeURI("strSpell="+strSpell+"&strFlag="+strFlag +"&searchCount=" + searchCount);
  22. return strXML;
  23. }
  24. //function ReturnResult(responseText)
  25. //{
  26. // alert(responseText);
  27. //}
  28. function send(AwtAjaxUrl, strSpell, strFlag, searchCount)
  29. {
  30. var strPostValue=XMLPattern(strSpell,strFlag,searchCount);
  31. xmlHttpRequest.open('POST', AwtAjaxUrl, true);
  32. xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  33. xmlHttpRequest.onreadystatechange = function() {
  34. if(xmlHttpRequest.readyState == 4)
  35. {
  36. switch (xmlHttpRequest.status)
  37. {
  38. case 404:
  39. alert('오류: ' + AwtAjaxUrl + '이 존재하지 않음');
  40. break;
  41. case 200:
  42. OnResult(xmlHttpRequest.responseText.trim());
  43. break;
  44. default:
  45. alert('오류: ' + xmlHttpRequest.responseText);
  46. break;
  47. }
  48. }
  49. }
  50. xmlHttpRequest.send(strPostValue);
  51. }
  52. String.prototype.trim = function ()
  53. {
  54. return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  55. }